3

The answers on how to spread table columns evenly under a multicolumn seem to suggest that this is not possible, e.g. https://tex.stackexchange.com/a/60604/36836. It seems hard to believe that LaTeX has this restriction.

Here is an example showing the basic problem of spreading columns evenly:

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

\begin{tabular}{cccc}
\toprule
 & \multicolumn{3}{c}{some longer text here}\\
\cmidrule{2-4}
 & 1 & 2 & 3\\
\midrule
some text here  & A    & B   & C   \\
\bottomrule
\end{tabular}

\end{document}

The last column, 3, take more space than the other columns.

enter image description here

Daniel
  • 1,787

2 Answers2

2

It seems the problem was putting LaTeX commands in front of \toprule.

Note that you only have to use \makebox in one row to establish the widths.

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

\savebox{\tempbox}{some longer text here}% measure width
\begin{tabular}{cccc}
\toprule
\dimen0=\dimexpr \wd\tempbox/3 - 4\tabcolsep/3\relax
 & \multicolumn{3}{c}{\usebox\tempbox}\\
\cmidrule{2-4}
 & \makebox[\dimen0]{1} & \makebox[\dimen0]{2} & \makebox[\dimen0]{3}\\
\midrule
some text here  & A    & B   & C   \\
\bottomrule
\end{tabular}

\end{document}

demo

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
1

You can try updating your source as follows. Change the position of column 3. Hope this helps.

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{cccl}
\toprule
 & \multicolumn{3}{c}{some longer text here}\\
\cmidrule{2-4}
 & 1 & 2 & 3\\
\midrule
some text here  & A    & B   & C   \\
\bottomrule
\end{tabular}

\end{document} 

Edit as per the comment. You can set the values in the tabular position environment as per your requirements. A sample have been shown below. Sorry for the late reply.

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\renewcommand*{\arraystretch}{1}
\begin{tabular}{lp{1cm}p{1cm}p{1cm}}
\toprule
 & \multicolumn{3}{c}{some longer text here}\\
\cmidrule{2-4}
 & 1 & 2 & 3\\
\midrule
some text here  & A    & B   & C   \\
\bottomrule
\end{tabular}
\end{document}
M S
  • 1,552
  • 1
    Thanks. That's better than the original but then there is still a large chunk of empty space. I'd prefer the distribution of space evenly. – Daniel Nov 11 '19 at 14:39
  • Okay. Check my recent edit. – M S Nov 11 '19 at 14:41
  • 1
    Great but not perfect because now one needs to set the column width manually, which is close to setting the table with manually. – Daniel Nov 11 '19 at 14:54
  • 1
    A small improvement of your code to get closer to the original's alignment is to add \usepackage{array} and use as column alignment l>{\centering}p{1cm}>{\centering}p{1cm}>{\centering}p{1cm}. – Daniel Nov 11 '19 at 14:55
  • Okay. Thanks Daniel. I will check your suggested command for sure. – M S Nov 11 '19 at 14:56
  • 1
    I guess the answer answers my question because I was not specific enough. So, I'll set it as the answer. Maybe I'll try to ask a more precise question later on. – Daniel Nov 11 '19 at 14:59
  • 2
    Or even nicer l *{3}{>{\centering}p{1cm}}. – Daniel Nov 11 '19 at 15:12
  • 1
    Or with wc{1cm} to ease centering. – TeXnician Nov 11 '19 at 20:22
  • @TeXnician: By "ease centering" you mean "center the content independently of the cell's width by overprinting", right? And wc{1cm} is a shortcut for w{c}{1cm}. – Daniel Nov 12 '19 at 08:40
  • 2
    @Daniel Yes, exactly. If the cell's content is short you can use the w type to avoid the need for centering (and correctives like arraybackslash). – TeXnician Nov 12 '19 at 09:13