I need to create some tables for a special college report. The data provided specifies the values column by column.
The user Andrew Swann pointed out, that there is a way to create TeX tables column by column which was completeley new to me, but would be a great benefit for my special purpose.
Unfortunately I neither understand those commands nor didn't find a good documentation for that. What I need is a table with borders around each single cell except for the first cell and the whole last row. Below is an example how it would look like using the regular syntax.
Could you please tell me how I can create such a table by building it columnwise?
\begin{tabular}{|l|l|l|}
\cline{2-3}
\multicolumn{1}{l|}{a} & b & c \\ \hline
d & e & f \\ \hline
g & h & i \\ \hline
\multicolumn{1}{l}{j} &
\multicolumn{1}{l}{k} &
\multicolumn{1}{l}{l} &
\end{tabular}
Best Answer
The macros
\halign
and\valign
are documented in the TeXbook. More accurately\halign
is described in detail there, and\valign
is introduced briefly, saying that is analogous.The
\valign
statement starts with a preamble than has the formthe table material is for the given column is inserted in place of the
#
's much as in macros. A short cut is that an extra&
at the beginning or immediately after another&
, means that the format material from that point up to the\cr
is repeated for all subsequent rows. Thus a preambleproduces an arbitrary number of rows with the same format.
In the table you add entries in the usual way; rows separated by
&
, column ending with\cr
. A complete column format specification can be replaced by other material via\noalign{...}
; so\noalign{\vrule}
produces a vertical rule the whole way down the table. A single row is replaced by writing\omit<...>
where<...>
is the new material. The analogue of\multicolumn
is\multispan
, thus\multispan3<...>
will spread<...>
over three rows.Here is your example:
The preamble says each row starts with a horizontal rule, a vertical space of
2pt
that can stretch followed by a horizontal box containing the material (padded with\quad
space on each size and with a guaranteed minimum height and depth from\strut
) followed by stretchable vertical space.\leaders\vrule\vfil
is what\vrulefill
ought to be, but the command happens not to be defined, this is used in combination with\multispan
to draw the vertical rules over the appropriate rows.When we use
\omit
for the box containinga
we have to provided the relevant parts of the formatting that we still need. The extra.4pt
on the\vskip
accounts for the thickness of the\hrule
.An alternative approach to the whole table would be to provide separate rows for the rules, but then this essentially doubles the number of
&
s we have to write.