2

Consider the following table

\begin{tabular}{cccccc}
    \toprule
    N   &       \multicolumn3c{L-family}    &   \multicolumn2c{H-family}    \\
    n   &   large   &   Large   &   LARGE   &       huge    &   Huge        \\
    \bottomrule
\end{tabular}

I want to emphasis the grouping of columns, hence the @-construction

\def\htc#1{ {\hskip#1\tabcolsep} }
\begin{tabular}{c  @\htc4  ccc  @\htc4  cc}
    \toprule
    N   &       \multicolumn3c{L-family}    &   \multicolumn2c{H-family}    \\
    n   &   large   &   Large   &   LARGE   &       huge    &   Huge        \\
    \bottomrule
\end{tabular}

Now I have to fine-tune the multicolumn because the horizontal space is off

\begin{tabular}{c  @\htc4  ccc  @\htc4  cc}
\toprule
N   &   \multicolumn3{@\htc{-3}c}{L-family} &   \multicolumn2{@\htc0c}{H-family}
\\
n   &   large   &   Large   &   LARGE       &       huge        &       Huge    
\\
\bottomrule
\end{tabular}

Why the dirty constants? Can it be done in a more automatic way?

MWE

\documentclass{article}
\usepackage{booktabs}
\begin{document}

\parskip1em

Consider the following table

\begin{tabular}{cccccc}
    \toprule
    N   &       \multicolumn3c{L-family}    &   \multicolumn2c{H-family}    \\
    n   &   large   &   Large   &   LARGE   &       huge    &   Huge        \\
    \bottomrule
\end{tabular}

~

I want to emphasis the grouping of columns, hence the @-construction

\def\htc#1{ {\hskip#1\tabcolsep} }
\begin{tabular}{c  @\htc4  ccc  @\htc4  cc}
    \toprule
    N   &       \multicolumn3c{L-family}    &   \multicolumn2c{H-family}    \\
    n   &   large   &   Large   &   LARGE   &       huge    &   Huge        \\
    \bottomrule
\end{tabular}

~

Now I have to fine-tune the multicolumn

\begin{tabular}{c  @\htc4  ccc  @\htc4  cc}
\toprule
N   &   \multicolumn3{@\htc{-3}c}{L-family} &   \multicolumn2{@\htc0c}{H-family}
\\
n   &   large   &   Large   &   LARGE       &       huge        &       Huge    
\\
\bottomrule
\end{tabular}

Why the dirty constantss?

\end{document}

PS In this question: Issue with alignment when using multi-column and @{\hskip}?, The answer suggests to suppress \tabcolsep using an empty @{}. One can see that this does not always give you the desired result.

4
  • 1
    Not bracing \multicolumn3c looks very weird but not bracing the @ expression looks positively dangerous. If you use the array package (which should almost always be used for tables) it does give the expected error. In the non array case you are relying on premature expansion of \htc to add the brace arguments for @ which sort of works by accident.. Commented Sep 25, 2020 at 21:55
  • Thanks for the reminder. \htc is the simplification I made for this post; in my document they are written in full. On the other hand, \multicolumn3c is intentional as they are rarely more than two tokens.
    – Symbol 1
    Commented Sep 25, 2020 at 22:05
  • but being single token here is the cause of the problem. I know it works but it looks so weird, and it will bite you. Commented Sep 25, 2020 at 22:07
  • Seeing your answer, I now can feel the bite =D
    – Symbol 1
    Commented Sep 25, 2020 at 22:09

2 Answers 2

1

The @ expressions are part of the right hand edge of the relevant column, so when using \multicolumn repeat the full component for the span including its right hand @ expression:

enter image description here

\documentclass{article}
\usepackage{booktabs}
\def\htc#1{ {\hskip#1\tabcolsep} }
\begin{document}

\parskip1em


I want to emphasis the grouping of columns, hence the @-construction


\begin{tabular}{c  @{\htc4}  ccc  @{\htc4}  cc}
    \toprule
    N   &       \multicolumn{3}{c@{\htc4}}{L-family}    &   \multicolumn{2}{c}{H-family}    \\
    n   &   large   &   Large   &   LARGE   &       huge    &   Huge        \\
    \bottomrule
\end{tabular}


\end{document}
1
  • Nice. So the key is the concept that c@{} is the correct grouping. Learn something everyday. Thank you so much. Didn't expect it to be so easy
    – Symbol 1
    Commented Sep 25, 2020 at 22:13
2

With {NiceTabular} of nicematrix and its built-in command \Block, you have directly the expected output.

\documentclass{article}
\usepackage{nicematrix}
\usepackage{booktabs}

\begin{document}

\NewDocumentCommand{\htc}{m}{\hspace{#1\tabcolsep}}

\begin{NiceTabular}{c@{\htc{4}}ccc@{\htc{4}}cc}
\toprule
N & \Block{1-3}{L-family}       &&& \Block{1-2}{H-family} \\
n & large &   Large   & LARGE     &  huge    &   Huge     \\
\bottomrule
\end{NiceTabular}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

1
  • Antiintuitive that it needs several compilation (because the original problem is at most a linear equation). That being said, thank you for suggesting new packages.
    – Symbol 1
    Commented Apr 27, 2021 at 1:31

You must log in to answer this question.

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