I have a table of two rows, the second one consists of 32 columns, each containing its column number (from 0 to 31). I want each column to use as little space as possible (no inter column space), since there are quite a lot of columns.
I have done this using @{}c@{}
. However, I don't like the fact that the columns are not all of the same size (due to the fact that some numbers have 2 digits, and others have only one). Hence I have manually added @{\hspace{0.7 mm}}c@{\hspace{0.7 mm}}
to each of the columns whose contents in the second row have only 1 digit (the first 10). I am quite pleased with the result.
My problem now is with the first row: the first row contains 4 columns, containing 0,1,2,3. Each column in the first row spans 8 columns of the second row. My problem is that the delimiters in the first row aren't aligned with the second row (in the sample below, notice that the delimiter between 7 and 8 is not aligned with the one above).
Is there an easier solution to my problem as a whole, or am I in the right direction and I just need to fix this alignment issue ?
Sample:
\begin{tabular}{|
% numbers with 1 digit
@{\hspace{0.7 mm}}c@{\hspace{0.7 mm}}|
@{\hspace{0.7 mm}}c@{\hspace{0.7 mm}}|
@{\hspace{0.7 mm}}c@{\hspace{0.7 mm}}|
@{\hspace{0.7 mm}}c@{\hspace{0.7 mm}}|
@{\hspace{0.7 mm}}c@{\hspace{0.7 mm}}|
@{\hspace{0.7 mm}}c@{\hspace{0.7 mm}}|
@{\hspace{0.7 mm}}c@{\hspace{0.7 mm}}|
@{\hspace{0.7 mm}}c@{\hspace{0.7 mm}}|
@{\hspace{0.7 mm}}c@{\hspace{0.7 mm}}|
@{\hspace{0.7 mm}}c@{\hspace{0.7 mm}}|
% numbers with 2 digits
@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|}
\hline
\multicolumn{8}{c|}{0}
&\multicolumn{8}{c|}{1}
&\multicolumn{8}{c|}{2}
&\multicolumn{8}{c|}{3}\\
\hline
0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24&25&26&27&28&29&30&31
\end{tabular}
Best Answer
It's easier. :) Set a length to the width of two digits in the current type size (I've also added a small space just in order that the figures don't touch the vertical lines) and the parameter
\tabcolsep
to zero; then usep
columns of the specified width and with\centering
alignment:If you don't want to use
\tabularnewline
, then add the magic\arraybackslash
: