Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
Welcome to TeX.sx! –  texenthusiast Mar 15 '13 at 17:03
    
I've taken the liberty of adding three statements at the beginning and one statement of the end of your code, in order to make it into a compilable MWE (minimum working example). –  Mico Mar 15 '13 at 18:28
    
@Mico: Thanks, I don't know why I didn't do that myself... –  Patrick Mar 15 '13 at 18:36
    
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 '13 at 18:38

1 Answer 1

up vote 2 down vote accepted

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...

share|improve this answer
    
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 '13 at 19:51
    
Glad to hear this! ---I don't think it would. –  Sašo Živanović Mar 15 '13 at 21:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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