Spacing between multicolumn tabular

multicolumntables

I want to generate a tabular that contains two header rows, the top row contains multicolumn's. I want to group certain columns with spacing between them, so I used @{\hskip}. The problem though is this increases the width of the right most column in each multicolumn so the header is no longer centred over the columns it spans.

How do I fix the alignment in the example table below so that the Col C header is in the middle of the four columns below it?

    \documentclass{article}
    \usepackage{booktabs}
    \begin{document}
    \begin{tabular}{@{}ll@{\hskip6em}l@{\hskip6em}llll@{\hskip6em}llll@{}} \toprule
      Col A &Col B & Col C & \multicolumn{4}{c}{Col D}& \multicolumn{4}{c}{Col E} \\
        &   &   & i & ii & iii & iv & i & ii & iii & iv \\  \midrule 
      ex1 & 100 & 200 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8   \\  \bottomrule
    \end{tabular}
    \end{document}

enter image description here

Best Answer

One option is to use the \extracolsep command instead of \hskip, which adds space to the left of the next column rather than at the end of the current one. However, because this affects all subsequent columns, you need to set it back to zero after the next column specifier, and, because this means using @, to avoid suppressing all space there, manually adding back in a space of 2\tabcolsep (for the spaces both to the right of that column and the left of the one after that):

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{@{}ll@{\hskip6em}l@{\hskip6em}llll@{\extracolsep{6em}}l@{\extracolsep{0pt}\hspace{2\tabcolsep}}lll@{}} \toprule
  Col A &Col B & Col C & \multicolumn{4}{c}{Col D}& \multicolumn{4}{c}{Col E} \\
    &   &   & i & ii & iii & iv & i & ii & iii & iv \\  \midrule 
  ex1 & 100 & 200 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8   \\  \bottomrule
\end{tabular}
\end{document}

extracolsep example

Related Question