4

The following table has two rows of headers, with the top row organizing categories over the second row using \multirow. The goal is to add blank space between the first group (columns 1-2) and the second group (columns 3-4), but not in between any other columns.

Minimum working example (may have added an extra package or two – sorry if so), with the same alignments as in my actual example, before I try any possible solutions:

\documentclass[hidelinks,12pt,fullpage]{article}
\usepackage[margin=0.8in]{geometry}
\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{clcl}
    \toprule
    \multicolumn{2}{c}{GG} & \multicolumn{2}{c}{GS} \\\cmidrule(lr){1-2}\cmidrule(lr){3-4}
    ID & \multicolumn{1}{c}{$P$} & ID & \multicolumn{1}{c}{$P$} \\
    \midrule
    1 & 1 & 33 & 2.5 \\
    2 & 0.9 & 34 & 2.25 \\
    \bottomrule
\end{tabular}
\end{document}

Output:

enter image description here

I've tried a variety of solutions to no avail. They all have basically the same problem. Consider this attempt, and then look at the output below.

\documentclass[hidelinks,12pt,fullpage]{article}
\usepackage[margin=0.8in]{geometry}
\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{cl@{\hspace{2em}}cl}
    \toprule
    \multicolumn{2}{c}{GG} & \multicolumn{2}{c}{GS} \\\cmidrule(lr){1-2}\cmidrule(lr){3-4}
    ID & \multicolumn{1}{c}{$P$} & ID & \multicolumn{1}{c}{$P$} \\
    \midrule
    1 & 1 & 33 & 2.5 \\
    2 & 0.9 & 34 & 2.25 \\
    \bottomrule
\end{tabular}
\end{document}

Output:

enter image description here

Notice that the second column is now wider than before. The \cmidrule on the left side now extends too far to the right, and the "P" in the second row, second column is also too far to the right. This seems to be actually extending the second column rather than adding space after it.

I've also tried adding a space before/after the @{\hspace{2em}} portion, using \hrule instead, using \qquad instead, and probably a few others. Also, I have a very, very tall table, so adding another "invisible" column in between columns 2 and 3 would be a huge pain. I'd really prefer to avoid that solution. Any other suggestions out there?

Thanks,

Matt

EDIT: The best solution without adding an extra column is as follows, from the answers below.

\documentclass[hidelinks,12pt,fullpage]{article}

\usepackage[margin=0.8in]{geometry}
\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{cl<{\hspace{2cm}}cl}
  \toprule
  \multicolumn{2}{c<{\hspace{2cm}}}{GG}
  & \multicolumn{2}{c}{GS}
  \\
  \cmidrule(lr{2cm}){1-2}\cmidrule(lr){3-4}
  ID & \multicolumn{1}{c<{\hspace{2cm}}}{$P$}
     & ID & \multicolumn{1}{c}{$P$} \\
  \midrule
  1 & 1 & 33 & 2.5 \\
  2 & 0.9 & 34 & 2.25 \\
  \bottomrule
\end{tabular}

\end{document}
3

One way to is to add extra space at the right of the second column and remember to include this in the relevant \multicolumn format specifications and the trimming of the corresponding cmidrule:

Sample output

\documentclass[hidelinks,12pt,fullpage]{article}

\usepackage[margin=0.8in]{geometry}
\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{cl<{\hspace{2cm}}cl}
  \toprule
  \multicolumn{2}{c<{\hspace{2cm}}}{GG}
  & \multicolumn{2}{c}{GS}
  \\
  \cmidrule(lr{2cm}){1-2}\cmidrule(lr){3-4}
  ID & \multicolumn{1}{c<{\hspace{2cm}}}{$P$}
     & ID & \multicolumn{1}{c}{$P$} \\
  \midrule
  1 & 1 & 33 & 2.5 \\
  2 & 0.9 & 34 & 2.25 \\
  \bottomrule
\end{tabular}

\end{document}

I use the < specification from the array package (which you already load via tabularx) instead of an @-expression to add additional space between columns, rather than replacing the standard separation.

2

for more space between the second and third group i would insert empty column, than make cmidrule slightly wider and for setting of numbers use S column type from siunitx package:

\documentclass[12pt,fullpage]{article}
\usepackage[margin=0.8in]{geometry}
\usepackage{amsmath}
\usepackage{booktabs, tabularx}
\usepackage{siunitx}

\begin{document}
\begin{tabular}{*{2}{S[table-format=2.2,
                       table-column-width=5ex]}
                    c
                *{2}{S[table-format=2.2,
                       table-column-width=5ex]}
                }
    \toprule
\multicolumn{2}{c}{GG}  &&  \multicolumn{2}{c}{GS}  \\
    \cmidrule(l{2pt}r{2pt}){1-2}
    \cmidrule(l{2pt}r{2pt}){4-5}
{ID}    &    {$P$}      &&  {ID}    &  {$P$}        \\
    \midrule
1       &   1           &&  33      &   2.5         \\
2       &   0.9         &&  34      &   2.25        \\
    \bottomrule
\end{tabular}
\end{document}

result:

enter image description here

if you like more space between groups GG and GS, you can add for example @{\hspace{2e}} after c:

\begin{tabular}{*{2}{S[table-format=2.2,
                       table-column-width=5ex]}
                    c@{\hspace{2em}}
                *{2}{S[table-format=2.2,
                       table-column-width=5ex]}
                }

column and obtain:

enter image description here

1

An easy solution is to add an additional column between columns 2 and 3. Add a \phantom entry to add whatever width you want.

\documentclass[hidelinks,12pt,fullpage]{article}
\usepackage[margin=0.8in]{geometry}
\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{clccl}
\toprule
\multicolumn{2}{c}{GG} &\phantom{mm}& \multicolumn{2}{c}{GS} \\\cmidrule(lr){1-2}\cmidrule(lr){4-5}
ID & \multicolumn{1}{c}{$P$} && ID & \multicolumn{1}{c}{$P$} \\
\midrule
1 & 1 && 33 & 2.5 \\
2 & 0.9 && 34 & 2.25 \\
\bottomrule
\end{tabular}
\end{document}

enter image description here

  • It's not a perfect solution, but it's doable. I also learned the \phantom command, so that you for that! I implemented this, and it works well enough, though copy/pasting the extra ampersand throughout the table was a pain. Thank you! – Matt McMahon Nov 3 '17 at 3:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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