# Improve intercolumn spacing of this table

I'm trying to spruce up the appearance of this table:

\begin{tabular}{rr@{\hspace{2em}}rr@{\hspace{2em}}rr@{\hspace{2em}}rr}
\toprule
\multicolumn{2}{c@{\hspace{2em}}}{\textbf{Word C}}&
\multicolumn{2}{c@{\hspace{2em}}}{\textbf{Char C}}&
\multicolumn{2}{c@{\hspace{2em}}}{\textbf{Chess}}&
\multicolumn{2}{c}{\textbf{Matching}}\\
\multicolumn{2}{c@{\hspace{2em}}}{\textbf{9 trials}}&
\multicolumn{2}{c@{\hspace{2em}}}{\textbf{9 trials}}&
\multicolumn{2}{c@{\hspace{2em}}}{\textbf{12 trials}}&
\multicolumn{2}{c}{\textbf{12 trials}}\\
$N$&$V$&$N$&$V$&$N$&$V$&$N$&$V$\\
\midrule
10 &  1 & 12 &  3 & 16 &  3 & 4 & 0 \\
10 &  1 & 12 &  6 & 16 &  3 & 4 & 0 \\
10 &  1 & 12 &  9 & 16 &  5 & 4 & 1 \\
10 &  2 & 24 &  6 & 16 &  5 & 4 & 1 \\
% ... many more rows ...
\bottomrule
\end{tabular}


Here's what it currently looks like. The biggest problem is that there's too much horizontal space between each N column and the corresponding V column, and that space is of variable size among the four groups.

What I want is for there to be a fixed, small distance between each N column and the corresponding V column; a larger distance between the group headings; and the N/V column pairs to be centered under their heading. The numbers in each column should continue to be right-justified. How might I accomplish this?

Note: all the elided rows contain numbers and only numbers, and there are no three-digit or larger numbers.

-
The different space between the N and V column is because the title cells span over both and have a different width. They are wider than the two columns and this pushes V to the right. –  Martin Scharrer Feb 19 '11 at 1:03
I figured, but I want it to put that extra space on either side of each N/V pair instead of in between N and V. –  Zack Feb 19 '11 at 1:39

Here's one, not wholly satisfactory solution.

\documentclass{article}
\usepackage{booktabs}
\newcommand\clap[1]{\hbox to0pt{\hss#1\hss}}
\newcommand\MC[1]{%
\multicolumn{2}{c@{\hspace{2em}}}{\clap{\textbf{#1}}}%
}
\begin{document}
\begin{tabular}{rr@{\hspace{2em}}rr@{\hspace{2em}}rr@{\hspace{2em}}rr}
\toprule
\MC{Word C}&
\MC{Char C}&
\MC{Chess}&
\MC{Matching}\\
\MC{9 trials}&
\MC{9 trials}&
\MC{12 trials}&
\MC{12 trials}\\
$N$&$V$&$N$&$V$&$N$&$V$&$N$&$V$\\
\midrule
10 &  1 & 12 &  3 & 16 &  3 & 4 & 0 \\
10 &  1 & 12 &  6 & 16 &  3 & 4 & 0 \\
10 &  1 & 12 &  9 & 16 &  5 & 4 & 1 \\
10 &  2 & 24 &  6 & 16 &  5 & 4 & 1 \\
% ... many more rows ...
\bottomrule
\end{tabular}
\end{document}


-
I was able to tweak this to get something satisfactory. Thanks for suggesting it -- I really ought to know by now that this trick is the first thing to try, but for some reason I never think of it. –  Zack Feb 22 '11 at 20:00
@Zach: I didn't spend too long on it, but I'm very curious what tweaks you made to make it satisfactory. You can edit it into my answer (and replace what I wrote, if you want). –  TH. Feb 22 '11 at 23:42
\documentclass{article}

\usepackage{array,booktabs,ragged2e}
\newcommand\MC[1]{\multicolumn{2}{@{}l}{\textbf{#1}}}

\def\SP{\hspace{15mm}}
\begin{document}

\begin{tabular}{@{} rl @{\SP} rl @{\SP} rl @{\SP} rl@{}}\toprule
\MC{Word C}  &\MC{Char C}  &\MC{Chess}    &\MC{Matching}\\
\MC{9 trials}&\MC{9 trials}&\MC{12 trials}&\MC{12 trials}\\
$N$&$V$&$N$&$V$&$N$&$V$&$N$&$V$\\\midrule
10 &  1 & 12 &  3 & 16 &  3 & 4 & 0 \\
10 &  1 & 12 &  6 & 16 &  3 & 4 & 0 \\
10 &  1 & 12 &  9 & 16 &  5 & 4 & 1 \\
10 &  2 & 24 &  6 & 16 &  5 & 4 & 1 \\
% ... many more rows ...
\bottomrule
\end{tabular}

\end{document}


-
This unfortunately sacrifices formatting that I need to keep: the V columns need to be right-justified (there are two-digit numbers in rows not included in the example). If I put that back, the trick you're using doesn't work anymore. –  Zack Feb 19 '11 at 16:49
Also, I implore you to think of the problem in terms of the N/V column pairs being too far apart instead of there being not enough space between groups. The available horizontal space for this table is extremely limited: I have to cut your \SP down to 8mm to avoid an overfull hbox, and even then it's too wide for aesthetics. –  Zack Feb 19 '11 at 16:58

Here is a Plain version, you can change the \groupheadingskip and \columnsepskip to your liking:

\documentclass{article}
\newskip\columnsepskip    \columnsepskip=1em
\newskip\rowsepskip       \rowsepskip=3pt
\begin{document}
\begin{table}
\vbox{\openup\rowsepskip\hrule height 1pt \medskip
\halign{&\tabskip\columnsepskip\hskip\groupheadingskip\hfil$#$&
\hfil$#$\hskip\groupheadingskip\cr
N&V&   N&V&   N&V&   N&V\cr
\noalign{\smallskip\hrule\medskip}
10&1&  12&3&  16&3&  4&0\cr
10&1&  12&6&  16&3&  4&0\cr
10&1&  12&9&  16&5&  4&1\cr
}
\medskip \hrule height 1pt
}
\end{table}
\end{document}


-
I'm committed to LaTeX for this document, but +1 for badass :) –  Zack Feb 19 '11 at 16:49
Nice! (Although it seems that the OP wants the alignment of the "V" column as in Niel's answer since there may be two digit numbers in those columns, too.) Note that you've got a spurious \bye at the end. –  Hendrik Vogt Feb 22 '11 at 8:00

It seems to me that, to provide space for the header to spread without affecting the data, you need more columns for the headers to spill into. Therefore, I recommend the following:

[Edit: I've incorporated elements of Herbert's post to obtain improved spacing of the headings, and also to condense the answer.]

\newlength\intercol
\setlength\intercol{0em}
\newlength\mycolwidth
\setlength\mycolwidth{1em}
\newcommand\head[1]{\parbox{\mycolwidth}{\hfill $#1$}}
\newcommand\MC[1]{\multicolumn{4}{@{}c@{}}{\textbf{#1}}}

\begin{tabular}%
{@{}crrc@{\hspace\intercol}crrc@{\hspace\intercol}crrc@{\hspace\intercol}crrc@{}}
\toprule
\MC{Word C}   &  \MC{Char C}    &  \MC{Chess}      &  \MC{Matching}
\\
\MC{9 trials}  &  \MC{9 trials}  &  \MC{12 trials}  &  \MC{12 trials}
\\
\\
\midrule
&   10 &  1     &&&     12 &    3   &&& 16  &   3       &&& 4   &   0   \\
&   10 &  1     &&&     12 &    6   &&& 16  &   3       &&& 4   &   0   \\
&   10 &  1     &&&     12 &    9   &&& 16  &   5       &&& 4   &   1   \\
&   10 &  2     &&&     24 &    6   &&& 16  &   5       &&& 4   &   1   \\
% ... many more rows ...
\bottomrule
\end{tabular}


Output:

• The lengths \intercol and \mycolwidth serve to determine the spacing between the column-quadruplets and the width of the data columns (the middle pair of each column quadruplet). The lengths are set to what seem æsthetically pleasing to me. (For data headings of N and V, 1em is about the minimum before you have problems.)

• The macro \head is defined to force the data columns to have the same width (i.e. to further encourage uniformity of spacing, despite any non-uniformity of the data); this forces the header to have the width described by \mycolwidth, which is ideally the maximum width of all data in the table. The extra \hfill in the macro forces the headers to be right-aligned (as the \parbox breaks alignment).

-
You can easily upload an image with the "add image" link (that you see above the composing window when you edit this answer). Or hit "Strg+G". –  Hendrik Vogt Feb 21 '11 at 16:35
@Hendrik Vogt: thanks for the tip, never thought to look there before. –  Niel de Beaudrap Feb 21 '11 at 16:59
I tried something very similar to this myself, but I couldn't get it to look quite right and the extra columns made it really hard to edit the contents of the table. –  Zack Feb 22 '11 at 20:01
@Zack: what didn't turn out properly about the appearance? (As for editing the data, I suppose that depending on how you populate the table, it can't be helped.) –  Niel de Beaudrap Feb 22 '11 at 21:43
there was extra spacing on the left of each column of numbers, no matter what I did. –  Zack Feb 22 '11 at 21:49

Unsurprisingly (as I write it), I'd use siunitx for a table of numbers like this. For me

\documentclass{article}
\usepackage{booktabs,siunitx}
\begin{document}
\sisetup{table-format=2.0}
\begin{tabular}{SSSSSSSS}
\toprule
\multicolumn{2}{c}{\textbf{Word C}}&
\multicolumn{2}{c}{\textbf{Char C}}&
\multicolumn{2}{c}{\textbf{Chess}}&
\multicolumn{2}{c}{\textbf{Matching}}\\
\multicolumn{2}{c}{\textbf{9 trials}}&
\multicolumn{2}{c}{\textbf{9 trials}}&
\multicolumn{2}{c}{\textbf{12 trials}}&
\multicolumn{2}{c}{\textbf{12 trials}}\\
$N$&$V$&$N$&$V$&$N$&$V$&$N$&$V$\\
\midrule
10 &  1 & 12 &  3 & 16 &  3 & 4 & 0 \\
10 &  1 & 12 &  6 & 16 &  3 & 4 & 0 \\
10 &  1 & 12 &  9 & 16 &  5 & 4 & 1 \\
10 &  2 & 24 &  6 & 16 &  5 & 4 & 1 \\
% ... many more rows ...
\bottomrule
\end{tabular}

\end{document}


looks fine. I'm not entirely clear what you mean about the spacing: LaTeX includes some inter-column space as standard, and to me the table looks readable without additional space being added.

For reference, what I get is

-
I think the OP doesn't like that there's more space between the columns "N" and "V" that belong to each other than between "V" and the next "N". (Then I'd agree with the OP.) Moreover, the "V" isn't aligned with its corresponding column. –  Hendrik Vogt Feb 19 '11 at 13:06
@Hendrik: I'm not entirely clear on the real nature of the data to be presented, but for the example you could improve the placement of "V" by setting [table-format=1.0] for the odd-numbered columns. I'll have to think about how I'd do the inter-column spacing as you describe. –  Joseph Wright Feb 19 '11 at 13:24
Hendrik is correct about how I want the inter-column spacing to look. The offset of the "V" is fine, because there are two-digit numbers in those columns in rows I didn't include in the example. And since all the numbers are just integers, I'm not really seeing what siunitx brings to the table here. –  Zack Feb 19 '11 at 16:51