3

I would like for columns A1, A3 and B1 to be more like column B3, which doesn't have any cell padding on the side facing out of its group.

Table with less than tight columns

Can I achieve that? The code I have right now looks like this:

\documentclass{article}
\usepackage{booktabs}
\begin{document}
  \begin{table*}\centering
    \begin{tabular}{@{}lccccccc@{}}\toprule
      & \multicolumn{3}{c}{A} & \phantom{abc}& \multicolumn{3}{c}{B}\\ \cmidrule{2-4} \cmidrule{6-8}
      & 1 & 2 & 3 && 1 & 2 & 3\\
      \midrule
      C     &       0.60  &       0.951 &       0.245         & &       1.151         &       1.563         &       0.586         \\
                  &     (0.262)         &     (0.364)         &     (0.310)         & &     (0.620)         &     (0.905)         &     (0.696)         \\
      \midrule
      \(N\)       &      919629         &      468093         &      451536         & &      186271         &       94771         &       91500         \\

      \bottomrule
    \end{tabular}
  \end{table*}
\end{document}
3
  • your columns in "A" parts are the same as in "B" parts of table. do you like to remove empty column between this two parts?
    – Zarko
    Mar 23, 2018 at 20:48
  • @Zarko No, the columns look differnt. As you can see the \cmidrule extends further to right in the A3 column than in the B3 column. If removing the empty column would help resolve my issue, then I am open to that.
    – Fredrik P
    Mar 23, 2018 at 21:00
  • yes, but this barely caught sight of it. the simple solution is remove all @{} in your table. however, see answers below for more "sophisticated" solutions :-)
    – Zarko
    Mar 23, 2018 at 21:13

5 Answers 5

4

In addition to getting rid of the empty column, I'd line up the numbers on their decimal markers, say, using the tools of the dcolumn package.

enter image description here

\documentclass{article}
\usepackage{booktabs,dcolumn}
\newcolumntype{d}[1]{D..{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\begin{document}
\begin{table}
\centering
\begin{tabular}{@{} l *{6}{d{2.4}} @{}}
\toprule
& \multicolumn{3}{c}{A} & \multicolumn{3}{c@{}}{B}\\ \cmidrule(lr){2-4} \cmidrule(l){5-7}
& \mc{1} & \mc{2} & \mc{3} & \mc{1} & \mc{2} & \mc{3} \\
\midrule
C & 0.60    & 0.951   & 0.245   & 1.151   & 1.563   & 0.586   \\
  & (0.262) & (0.364) & (0.310) & (0.620) & (0.905) & (0.696) \\
\midrule
$N$ & \mc{919629} & \mc{468093} & \mc{451536} & \mc{186271} &  \mc{94771} &  \mc{91500} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
3
  • Very nice! There wouldn't be some way to increase the space between A3 and B1 without adding a phantom column inbetween them?
    – Fredrik P
    Mar 24, 2018 at 20:44
  • @FredrikP - In my experience, tables with noticeably different amounts of inter-column whitespace quickly risk looking either unbalanced or, worse, amateurish. Thus, if you want to increase the space between A3 and B1, you should probably widen the other inter-column spaces as well. E.g., change \begin{tabular}{@{} l *{6}{d{2.4}} @{}} to \setlength\tabcolsep{0pt} \begin{tabular*}{0.9\textwidth}{l @{\extracolsep{\fill}} *{6}{d{2.4}} }. (Of course, change \end{tabular} to \end{tabular*} as well.) Feel free to adjust the overall width (0.9\textwidth) to suit your taste.
    – Mico
    Mar 24, 2018 at 22:22
  • Albeit it might be ill-advised, is there some way to do it? To be clear, I would like to both the space between the first and second columns and the space between the fourth and fifth column. I think that would look balanced. It’s just that I can’t figure out how to increase the second space without an extra column.
    – Fredrik P
    Mar 25, 2018 at 6:43
6

i would write your table slightly different:

enter image description here

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}% added

\begin{document}
  \begin{table*}\centering
\begin{tabular}{ l *{6}{S[input-symbols = ( ),
                          table-space-text-pre={(},
                          table-space-text-post={)},
                          table-format=1.3]} }% changed
    \toprule
        & \multicolumn{3}{c}{A}                         & \multicolumn{3}{c}{B}                         \\
    \cmidrule(lr){2-4}
    \cmidrule(lr){5-7}
        & {1}           & {2}           & {3}           & {1}           & {2}           & {3}           \\
    \midrule
C       &  0.60         &  0.951        &  0.245        &  1.151        &  1.563        &  0.586        \\
        & (0.262)       & (0.364)       & (0.310)       & (0.620)       & (0.905)       & (0.696)       \\
  \midrule
\(N\)   & \num{919629}  & \num{468093}  & \num{451536}  & \num{186271}  & \num{94771}   & \num{91500}   \\ %changed
    \bottomrule
\end{tabular}
  \end{table*}
\end{document}

or eventualy:

enter image description here

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
  \begin{table*}\centering
\begin{tabular}{ l *{3}{S[input-symbols = ( ),
                          table-space-text-pre={(},
                          table-space-text-post={)},
                          table-format=1.3]}
                    c
                   *{3}{S[input-symbols = ( ),
                          table-space-text-pre={(},
                          table-space-text-post={)},
                          table-format=1.3]} }
    \toprule
        & \multicolumn{3}{c}{A}                         && \multicolumn{3}{c}{B}                        \\
    \cmidrule(lr){2-4}
    \cmidrule(lr){6-8}
        & {1}           & {2}           & {3}           && {1}          & {2}           & {3}           \\
    \midrule
C       &  0.60         &  0.951        &  0.245        &&  1.151       &  1.563        &  0.586        \\
        & (0.262)       & (0.364)       & (0.310)       && (0.620)      & (0.905)       & (0.696)       \\
  \midrule
\(N\)   & \num{919629}  & \num{468093}  & \num{451536}  && \num{186271} & \num{94771}   & \num{91500}   \\
    \bottomrule
\end{tabular}
  \end{table*}
\end{document}

(difference is in inserted empty column which add more space between table part A and B.

2
  • I like that you managed to add space between the columns without the extra column, but your solution causes the line below B not to reach all the way out to the right-hand side of the table.
    – Fredrik P
    Mar 24, 2018 at 19:56
  • @FredrikP, `lines below A and B are deliberately select to be equal and slightly shorter than width of the columns below them. if you not liked this, then remove . increasing space between A and B parts without introduce new column (which is the simplest way) is not trivial, since extending space might introduce asymmetry in columns width. i will not do this.
    – Zarko
    Mar 24, 2018 at 20:11
4

Use (lr) combinations with your \cmidrules and remove \phantom{abc}, it adds too much space.

\documentclass{article}
\usepackage{booktabs}
\begin{document}
  \begin{table*}\centering
    \begin{tabular}{@{}lccccccc@{}}
        \toprule
                                             &    \multicolumn{3}{c}{A}    &  &    \multicolumn{3}{c@{}}{B}    \\
        \cmidrule(lr){2-4} \cmidrule(l){6-8} &    1    &    2    &    3    &  &    1    &    2    &    3    \\ \midrule
        C                                    &  0.60   &  0.951  &  0.245  &  &  1.151  &  1.563  &  0.586  \\
                                             & (0.262) & (0.364) & (0.310) &  & (0.620) & (0.905) & (0.696) \\ \midrule
        \(N\)                                & 919629  & 468093  & 451536  &  & 186271  &  94771  &  91500  \\ \bottomrule
    \end{tabular}
  \end{table*}
\end{document}

enter image description here

1
  • Very nice! This solves it. I awarded the answer to @Mico simply b/c of posting first.
    – Fredrik P
    Mar 24, 2018 at 19:58
3

I'd suggest the following:

\documentclass{article}
\usepackage{booktabs}
\begin{document}
  \begin{table*}\centering
    \begin{tabular}{@{}l@{\hskip\tabcolsep}@{}ccc@{}c@{\hskip\tabcolsep}@{}ccc@{}}\toprule
      & \multicolumn{3}{c}{A} & \phantom{abc}& \multicolumn{3}{c}{B}\\ \cmidrule{2-4} \cmidrule{6-8}
      & 1 & 2 & 3 && 1 & 2 & 3\\
      \midrule
      C     &       0.60  &       0.951 &       0.245 & &       1.151 &       1.563   &       0.586    \\
            &     (0.262) &     (0.364) &     (0.310) & &     (0.620) &     (0.905)   &     (0.696)    \\
      \midrule
      \(N\) &      919629 &      468093 &      451536 & &      186271 &       94771   &       91500    \\

      \bottomrule
    \end{tabular}
  \end{table*}
\end{document}

enter image description here

1
  • Very nice! This solves it. I awarded the answer to @Mico simply b/c of posting first.
    – Fredrik P
    Mar 24, 2018 at 19:58
0

This is fixed by changing

\begin{tabular}{@{}lccccccc@{}}

to

\begin{tabular}{@{}l@{}ccc@{}c@{}ccc@{}}
1
  • 1
    This also removes the right tabcolsep of the first column and leads to a very small distance between 'N' and '919629'.
    – leandriis
    Mar 23, 2018 at 21:07

You must log in to answer this question.

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