1

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

1 Answer 1

2

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

1
  • Thanks, thats exactly what I needed Commented May 17, 2022 at 4:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .