The ctable package^{∗} for use with L^{A}TEX2e

Wybo Dekker

                     wybo@servalys.nl

2003/04/06

List of Tables

1 The Skewing Angles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 Example with a specified width of 100mm . . . . . . . . . . . . . . . . . . 3

List of Figures

1 The di- and tri-bromobenzenes . . . . . . . . . . . . . . . . . . . . . . . . 5

1 Purpose

The ctable package lets you easily typeset centered, captioned table and figure floats with optional footnotes. Both caption and footnotes will be forced within the width of the table. If the width of the table is specified, then tabularx will be used to typeset it, and the X column specifier can be used. Otherwise tabular will be used. This package defines the commands \ctable, \tnote and \tmark, as well as four \tabularnewline generating commands. The latter generate reasonable amounts of whitespace around horizontal rules and are also useful for tabulars outside this package. Since the ctable package imports the array and booktabs packages, all commands from those packages are available as well. Note that, in line with the comments that Simon Fear made describing his booktabs package, vertical rules for column separation can be produced with \ctable, but no provisions are made to have them make contact with horizontal rules.

2 Usage

\ctable \ctable is called with 4 parameters, of which the first is optional:

\ctable[options]       % key=value,...
       {coldefs}       % for \begin{tabular}
       {foottable}     % zero or more \tnote commands (see below)
       {table lines}   % lines for the table

Options are given as key=value pairs, separated by comma’s. Extra comma’s, including one behind the last pair, don’t hurt. Currently the following option keys have been defined:

∗This file has version number v1.4, dated 2003/04/06.

caption table caption
cap  for a short caption to go to the \tableofcontents
pos  float position, default: tbp
label  for \label
width  for tabularx; if absent, tabular will be used
figure produce a figure float instead of a table float
botcap put the caption at the bottom of the float instead of on top of it

rotate rotate table or figure by 90 degrees anticlockwise and put it on a separate page.

If you use this option, the pos option is not allowed

star use the starred versions of the table and figure environments, which place the float over two columns when the twocolumn option or the \twocolumn command is active

The footnotes are placed under the table, without a rule. You therefore probably will want to use the \LL (last line) command if you use footnotes.

\tnote \tnote[label]{footnote text} places ^{label} footnote text under the table. Can only be used in the foottable parameter described above. The label is optional, the default label is a single a. For more detailed control, you can also replace this command with something

like labeltext&footnotetext\NN.

\tmark \tmark[label] this command places the superscripted label in the table. It is equivalent with $^{label}$. The label is optional, the default label is a single a. The newline generating commands are a combination of \tabularnewline and zero or

one of booktabs’ \toprule, \midrule or \bottomrule. These combinations have been

made, and short names have been defined, because source texts for complex tables often become very crowded:

\NN Normal Newline, generates just a normal new line. An optional dimen parameter inserts

extra vertical space under the line \FL First Line, generates a new line and a thick rule with some extra space under it. An optional

dimen parameter sets the line width; the default is 0.08em \ML Middle Line: generates a new line and a thin rule with some extra space over and under it.

An optional dimen parameter sets the line width; the default is 0.05em \LL Last Line: generates a new line and a thick rule with some extra space over it. An optional

dimen parameter sets the line width; the default is 0.08em These macros can be used outside \ctable constructs. Finally, for completeness, here are some of booktabs’ commands that may be useful:

\toprule \toprule[<wd>] where <wd> is the optional thinkness of the rule

\midrule  \midrule[<wd>]
\bottomrule  \bottomrule[<wd>]
\cmidrule  \cmidrule[<wd>](<trim>){a-b} where <trim> can be r, l, or rl and the rule is drawn

over columns a through b

\morecmidrules \morecmidrules must be used to separate two successive cmidrules

\addlinespace  \addlinespace[<wd>] inserts extra space between rows
\specialrule  \specialrule{<wd>}{<abovespace>}{<belowspace>}

See the booktabs documentation for details.

3 Examples

3.1 Tables

Table 1 is an example taken from the related package threeparttable.sty by Donald Arseneau, with an extra footnote. It was typeset with:

 \ctable[cap     = The Skewing Angles,
         caption = The Skewing Angles ($\beta$) for

Table 1: The Skewing Angles (β) for Mu(H) + X_{2} and Mu(H) + HX^{a}

H(Mu) + F_{2} H(Mu) + Cl_{2}
β(H)  80.9^{∘}^{b}  83.2^{∘}
β(Mu)  86.7^{∘}  87.7^{∘}

a

for the abstraction reaction, Mu + HX → MuH + X.

b 1 degree = π/180 radians.

c

this is a particularly long note, showing that footnotes are set in raggedright mode as we don’t like hyphenation in table footnotes.

Table 2: Example with a specified width of 100mm

Example using tabularx

Multicolumn entry!  THREE FOUR

one The width of this column depends on the width of the table.^{a} three Column four will act in the same way as column two, with the same width.

a footnotes are placed under the table

           $\fam0 Mu(H)+X_2$ and $\fam0 Mu(H)+HX$~\tmark,
 label   = tab:nowidth,
]
{rlcc}
{\tnote{for the abstraction reaction,
        $\fam0 Mu+HX \rightarrow MuH+X$.}
 \tnote[b]{1 degree${} = \pi/180$ radians.}
 \tnote[c]{this is a particularly long note, showing that
           footnotes are set in raggedright mode as we don't like
           hyphenation in table footnotes.}
}{\FL
    &            & $\fam0 H(Mu)+F_2$     & $\fam0 H(Mu)+Cl_2$
  \ML
    &$\beta$(H)  & $80.9^\circ$\tmark[b] & $83.2^\circ$
  \NN
    &$\beta$(Mu) & $86.7^\circ$          & $87.7^\circ$
  \LL
}

Table 2 is an example with a width specification, taken from the tabularx documentation, with the vertical rules removed, and typeset with:

\ctable[caption = Example with a specified width of 100mm,
 width   = 100mm,
 pos     = t,
 label   = tab:width,
]
{c>{\raggedright}Xc>{\raggedright}X}

{\tnote{footnotes are placed under the table}}
{\FL
\multicolumn{4}{c}{Example using tabularx}
\ML
\multicolumn{2}{c}{Multicolumn entry!} & THREE & FOUR
\ML
one&
The width of this column depends on the
width of the table.\tmark &
three&
Column four will act in the same way as
column two, with the same width.
\LL
}

3.2 Figures

Figures, even single ones, are always put in tabular cells. This is not particularly handy for single pictures, but it eases the construction of arrays of pictures, including sub-captions, delineation, and spacing. Figure 1 shows a figure that has been produced with the \ctable command, in combination with \usepackage{carom}; it has been typeset with:

\ctable[caption=The di- and tri-bromobenzenes,
 botcap,
 figure,
]{ccc}{}{            \FL
\bzdrv{1==Br;2==Br}&
\bzdrv{1==Br;3==Br}&
\bzdrv{1==Br;4==Br}        \NN
1,2 & 1,3 & 1,4            \ML
\bzdrv{1==Br;2==Br;3==Br}&
\bzdrv{1==Br;2==Br;4==Br}&
\bzdrv{1==Br;3==Br;5==Br}  \NN
1,2,3 & 1,2,4 & 1,3,5      \LL
}

(The excessive whitespace at the left of the figure is caused by the bounding boxes generated by the carom package.)

4 Implementation

1⟨∗package ⟩

2\RequirePackage{keyval,array,tabularx,booktabs,rotating}

3

4\def\NN{\tabularnewline}
5\def\FL{\toprule}
6\def\ML{\NN\midrule}
7\def\LL{\NN\bottomrule}

8

9\newcommand{\tnote}[2][a]{%
10 \hbox{\@textsuperscript{\normalfont\textit{#1}}}&#2\NN}
11\newcommand{\tmark}[1][a]{%
12 \hbox{\@textsuperscript{\normalfont\textit{#1}}}}

13

[figure: Br; Br; Br; Br; Br; Br]
1,2  1,3  1,4

[figure: Br; Br; Br; Br; Br; Br; Br; Br; Br]
1,2,3  1,2,4  1,3,5

Figure 1: The di- and tri-bromobenzenes

Option setting commands from keyval. The table position (here, top, bottom, page) gets a special treatment, since L^{A}TEX does not expand commands there. So instead of putting things like tbp in a command like \ctblbegin we put \begin{table}[tbp] in it.

14\define@key{ctbl}{caption} {\def\ctblcaption {#1}}
15\define@key{ctbl}{cap}     {\def\ctblcap     {#1}}
16\define@key{ctbl}{label}   {\def\ctbllabel   {#1}}
17\define@key{ctbl}{pos}     {\def\ctblpos{#1}\def\ctblbegin   {\ctblbeg[#1]}}
18\define@key{ctbl}{width}   {\def\ctblwidth   {#1}}
19\define@key{ctbl}{botcap}[]{\def\ctblbotcap  {1}}
20\define@key{ctbl}{rotate}[]{\def\ctblrotate  {sideways}}
21\define@key{ctbl}{figure}[]{\def\ctbltaborfig{figure}}
22\define@key{ctbl}{star}  []{\def\ctblstarred {*}}

23

24\def\ctblCaption{
25 \ifx\ctblcap\empty\let\ctblcap\ctblcaption\fi%
26 \ifx\ctblcaption\empty\else
27  \caption[\ctblcap]{\label{\ctbllabel}\ctblcaption}
28 \fi

29}

Allocate a box register for use by the \ctable command.

30\newbox\ctbl@tabel

31

32\newcommand{\ctable}[4][]{%
33 \def\ctbltaborfig{table}%
34 \def\ctblrotate  {}%
35 \def\ctblpos     {}%
36 \def\ctblcaption {}%
37 \def\ctblcap     {}%
38 \def\ctbllabel   {}%
39 \def\ctblbeg     {\begin{\ctblrotate\ctbltaborfig\ctblstarred}}%
40 \def\ctblbegin   {\ctblbeg}%
41 \def\ctblend     {\end{\ctblrotate\ctbltaborfig\ctblstarred}}%
42 \def\ctblwidth   {}%
43 \def\ctblbotcap  {}%

44 \def\ctblstarred {}%
45 \setkeys{ctbl}{#1}%
46 \ifx\ctblpos\empty\else%
47  \ifx\ctblrotate\empty\else%
48  \PackageError{ctable}{%
49  You may not use pos and rotate options together}{%
50  Rotated tables and figures are always typeset on a separate page}
51  \fi
52 \fi
53 % save the table contents in a box, so we can determine its width:
54 \sbox\ctbl@tabel{%
55  \ifx\ctblwidth\empty
56  \begin{tabular}{#2}%
57  #4%
58  \end{tabular}%
59  \else
60  \begin{tabularx}{\ctblwidth}{#2}%
61  #4%
62  \end{tabularx}%
63  \fi
64 }%
\ctblbegin is now defined as something like \begin{table}[tbp].
65 \ctblbegin
66  \begin{center}%
67  \begin{minipage}{\wd\ctbl@tabel}%
68  \ifx\ctblbotcap\empty\ctblCaption\vspace{2ex}\fi
69  \usebox\ctbl@tabel % insert the tabular
70  \def\ctblfootnotes{#3}%
71  \ifx#3\empty\else % append footnotes, if any
72  \\%
73  \begin{tabularx}{\hsize}{r@{\,}>{\footnotesize\raggedright}X}%
74  #3%
75  \end{tabularx}%
76  \fi
77  \ifx\ctblbotcap\empty\else\ctblCaption\fi
78  \end{minipage}%
79  \end{center}%
80 \ctblend%

81} 82⟨/package ⟩