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:
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:
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}