7

I'm trying to use the booktabs package, and I'm trying to make tables with "column groups" that are delimited by extra space. In the following, I am doing this using the @{} syntax in the tabular environment header. Unfortunately, however, this seems to ruin the alignment of the multicolumns and the cmidrules. Any ideas how I can fix this?

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}
 \centering
 \begin{tabular}{cc @{\hskip 4\tabcolsep}
    *{2}{c} @{\hskip 4\tabcolsep}
    *{2}{c} @{\hskip 4\tabcolsep}
    *{2}{c} }
  \toprule
  & & \multicolumn{2}{c}{A} & \multicolumn{2}{c}{B} &  
\multicolumn{2}{c}{C}\\
  \cmidrule(lr){3-4} \cmidrule(lr){5-6}
\cmidrule(lr){7-8}
  & D & E & F & E & F & E & F\\
  \midrule
  G    & 4.6 & 1.7 & 0.35 & 0.30 & 0.5 & 0.21 & 0.24\\
  H    & 6.5 & 2.7 & 1.4  & 1.2  & 1.3  & 0.30 & 5\\
  I    & 8.7 & 7.3 & 4.6  & 8.5  & 89.3  & 3.7  & 2\\
  J    & 1.4  & 13  & 9.7  & 13   & 8.7  & 8.2   & 4\\
  K    & 5 & 2  & 85   & 18   & 74   & 2.9   & 0.24\\
  \bottomrule
  \end{tabular}
\end{table}
\end{document}
1
  • rather than altering the column width, I could also use phantom columns, but they seem a little wide and I run into the same problem of adjusting individual column widths
    – Patrick
    Mar 15, 2013 at 18:38

1 Answer 1

4

Two things help, in conjunction:

  1. Adjusting the header of \multicolumns to @{}c@{\hskip 4\tabcolsep} --- this deals with the alignment
  2. Adjusting the right trim of \cmidline: (lr{\dimexpr 4\tabcolsep+0.5em}) --- this deals with line lengths

The full code of the upper part of the table is thus:

  \toprule
  & & \multicolumn{2}{@{}c@{\hskip 4\tabcolsep}}{A} & \multicolumn{2}{@{}c@{\hskip 4\tabcolsep}}{B} &  
\multicolumn{2}{c}{C}\\
  \cmidrule(lr{\dimexpr 4\tabcolsep+0.5em}){3-4} \cmidrule(lr{\dimexpr 4\tabcolsep+0.5em}){5-6}
\cmidrule(lr){7-8}
  & D & E & F & E & F & E & F\\
  \midrule

I suspect you will want to further tweak the line lenghts and/or use decimal point alignment...

3
  • Thanks, that works like a charm! You are right, though, I needed to tweak the lines a bit. Decimal point alignment would be nice, would this cause problems in the alignment?
    – Patrick
    Mar 15, 2013 at 19:51
  • Glad to hear this! ---I don't think it would. Mar 15, 2013 at 21:44
  • According to this answer, you should never use \hskip in LaTeX code. Use \hspace{4\tabcolsep} here.
    – moi
    Mar 5, 2021 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.