[Tex/LaTex] Table with gap between cmidrule’s (extra space between two columns)

tables

Example of my final solution based on Werner's suggestion can be found at the end of this question.

I would like to make a table that looks about as this one:

Example table created in excel

I can get most of this to work with the following code:

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{table}\centering
\begin{tabular}{l c c c c}
\toprule
    & \multicolumn{2}{c}{Text1} & \multicolumn{2}{c}{Text2} \\ 
    \cmidrule{2-3} \cmidrule{4-5}
    & A & B & A & B \\
    \midrule
Foo & 1 & 2 & 3 & 4\\
\bottomrule
\end{tabular}
\caption{Foo matter}
\end{table}

\end{document}

which gives me this result:

Latex table

So far the only solution (that kind of works) that I could come up with is to add an empty column between column 3 and 4. I was however hopping that there is an easy solution that allows me to directly add some space between the two columns.

This solution seems to be pretty close to what I would like but causes some problems with the last three columns (they do not appear to be cantered). Adding

\usepackage{array}
\newcolumntype{C}{@{\extracolsep{3cm}}c@{\extracolsep{0pt}}}%

to the preamble and changing begin tabular to

\begin{tabular}{l c c C c}

gives me:

So close

That is close but not quite what I need.

I did also find a few solutions to insert a space between rows but could not transfer them to columns: Row Space 1 and others.

Solution based on answer by Werner

The solution for me is mostly what Werner suggested. I have only added values for how much the lines should be trimmed on either side.
To get:

The table I wanted

I used:

\documentclass{article}

\usepackage{booktabs}
\usepackage{array}
\newcolumntype{C}{@{\extracolsep{3cm}}c@{\extracolsep{0pt}}}%

\begin{document}

\begin{table}\centering
\begin{tabular}{l c c c c}
\toprule
    & \multicolumn{2}{c}{Text1} & \multicolumn{2}{c}{Text2} \\ 
    \cmidrule(l{2pt}r{2pt}){2-3} \cmidrule(l{2pt}r{2pt}){4-5}
    & A & B & A & B \\
    \midrule
Foo & 1 & 2 & 3 & 4\\
\bottomrule
\end{tabular}
\caption{Foo matter}
\end{table}

\end{document}

Best Answer

The only way to break the horizontal rule would be to insert a separate column (as you suggest), or to marginally trim the \cmidrules using the optional (..) specification:

enter image description here

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{tabular}{l c c c c}
  \toprule
  & \multicolumn{2}{c}{Text1} & \multicolumn{2}{c}{Text2} \\
  \cmidrule{2-3} \cmidrule{4-5}
  & A & B & A & B \\
  \midrule
  Foo & 1 & 2 & 3 & 4 \\
  \bottomrule
\end{tabular}

\bigskip

\begin{tabular}{l c c c c}
  \toprule
  & \multicolumn{2}{c}{Text1} & \multicolumn{2}{c}{Text2} \\
  \cmidrule(lr){2-3} \cmidrule(lr){4-5}
  & A & B & A & B \\
  \midrule
  Foo & 1 & 2 & 3 & 4 \\
  \bottomrule
\end{tabular}

\bigskip

\begin{tabular}{l c c c c c}
  \toprule
  & \multicolumn{2}{c}{Text1} & & \multicolumn{2}{c}{Text2} \\
  \cmidrule{2-3} \cmidrule{5-6}
  & A & B & & A & B \\
  \midrule
  Foo & 1 & 2 & & 3 & 4 \\
  \bottomrule
\end{tabular}

\end{document}

Adding space in the column specification using

\begin{tabular}{l c c@{\hspace{1cm}} c c}

inserts 1cm between columns 3 and 4, but would require you to correct alignment when using \multicolumn without providing the gap.

I don't think inserting an empty column is that bad. You could actually control the width of the column to provide a finely-tuned spacing of the \cmidrule separation. Something like

\begin{tabular}{l c c c@{\hspace{1cm}} c c}

Would give a gap of exactly 1cm between columns 3 and (now) 5.

Related Question