0

I'm using the booktabs and siunitx packages to typeset scientific quantities in a table.

It is known that for long column headings -- created using the multicolumn command in the booktabs package -- the extra column width is assigned to the last column of the multicolumn. Table 1 below shows an example (vertical grids are shown to emphasize the column widths).

I noticed that the siunitx package has an option table-column-width to set fixed column widths. I decided to try to use this option to force each of my three columns labeled by multicolumn to have one-third the width of the multicolumn heading.

So in the MWE below, I used \newlength and \settowidth to store the length, in pt, of the multicolumn heading in myl. The use of \the\myl indicates that the multicolumn heading is 128.6415pt. 128.6415 divided by 3 is approximately 42.88, so in Table 2 below I set table-column-width to 42.88pt for each of the multicolumn columns.

Table 2 looks better than Table 1, but why is the total width of the multicolumn significantly larger than the apparent width of Long parameter, $\alpha$ (\si{\kilo\newton\per\kilo\gram})?

\documentclass{article}

\usepackage{amsmath,siunitx,booktabs} \sisetup{% detect-family, detect-shape, detect-weight, detect-mode, product-units = power, list-final-separator = {, and }, retain-explicit-plus, input-comparators = {<=>\approx\ge\geq\gg\le\leq\ll\sim\lesssim\gtrsim} }

\begin{document}

% Table 1 \begin{table}[!h] \centering \begin{tabular}{l| S[table-format=1.1,table-number-alignment=left]| S[table-format=1.1,table-number-alignment=left]| S[table-format=1.1,table-number-alignment=left]|} \toprule & \multicolumn{3}{c}{Long parameter, $\alpha$ (\si{\kilo\newton\per\kilo\gram})} \ \cmidrule(lr){2-4} & {$\alpha_1$} & {$\alpha_2$} & {$\alpha_3$} \ Trial A & 1.1 & 2.2 & 3.3 \ \bottomrule \end{tabular}\caption{Problem (MWE)} \end{table}

% Store the length of the multicolumn header in \myl \newlength{\myl} \settowidth{\myl}{Long parameter, $\alpha$ (\si{\kilo\newton\per\kilo\gram})} \the\myl

% Table 2 \begin{table}[!h] \centering \begin{tabular}{l| S[table-format=1.1,table-number-alignment=left,table-column-width=42.88pt]| S[table-format=1.1,table-number-alignment=left,table-column-width=42.88pt]| S[table-format=1.1,table-number-alignment=left,table-column-width=42.88pt]|} \toprule & \multicolumn{3}{c}{Long parameter, $\alpha$ (\si{\kilo\newton\per\kilo\gram})} \ \cmidrule(lr){2-4} & {$\alpha_1$} & {$\alpha_2$} & {$\alpha_3$} \ Trial A & 1.1 & 2.2 & 3.3 \ \bottomrule \end{tabular}\caption{Attempt at solution} \end{table}

\end{document}

output

Andrew
  • 1,249
  • 1
    you need to span the two central column dividers so 2\arrayrulewidth+4\tabcolsep as well as the columns, so need to add that to your measured length – David Carlisle Jan 21 '22 at 19:24

1 Answers1

1

Like this?

enter image description here

Last three columns should have equal, long enough width. You my consider X columns type (defined in tabularx and also in tabularray package and then sett table width accordingly (by trial). Wit latter option, the MWE is:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx, varwidth}

\begin{document} \begin{table}[ht] \centering \sisetup{table-format=1.1, table-number-alignment=left} \begin{tblr}{width=0.6\linewidth, vlines, colspec = {l *{3}{X[c, si]} }, row{2} = {mode=math}, measure = vbox } \toprule & \SetCell[c=3]{c} {{{Long parameter, $\alpha$ (\si{\kilo\newton\per\kilo\gram})}}} & & \ \cmidrule{2-4} & {{{\alpha_1}}} & {{{\alpha_2}}} & {{{\alpha_3}}} \ \midrule Trial A & 1.1 & 2.2 & 3.3 \ \bottomrule \end{tblr} \caption{Problem (MWE)} \end{table} \end{document}

Edit: or by calculating of columns widths from width of multi column cell In this case you need to define new lenght, for example \colwidth:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx, varwidth}
\newlength{\colwidth}

\begin{document} \begin{table}[ht] \centering \sisetup{table-format=1.1, table-number-alignment=left} \settowidth\colwidth{Long parameter, $\alpha$ (\si{\kilo\newton\per\kilo\gram})} \begin{tblr}{vlines, colspec = {l *{3}{Q[c, si, wd=\colwidth/3]} }, row{2} = {mode=math}, measure = vbox } \toprule & \SetCell[c=3]{c} {{{Long parameter, $\alpha$ (\si{\kilo\newton\per\kilo\gram})}}} & & \ \cmidrule{2-4} & {{{\alpha_1}}} & {{{\alpha_2}}} & {{{\alpha_3}}} \ \midrule Trial A & 1.1 & 2.2 & 3.3 \ \bottomrule \end{tblr} \caption{Problem (MWE)} \end{table} \end{document}

enter image description here

BTW, formatting of cells with numbers is a bit unusual. People prefer to have centered numbers as well column header:

enter image description here

If you liked this, then remove option table-number-alignment=left from \sisetup.

Edt(2): and finally solution with standard table and defining S column width. Here observe of order of settings:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{makecell, siunitx}

\newlength{\colwidth}

\begin{document} \begin{table}[ht] \centering \renewcommand\arraystretch{1.2} \settowidth\colwidth{Long parameter, $\alpha$ (\si{\kilo\newton\per\kilo\gram})} \sisetup{table-format=1.1, table-column-width=\colwidth/3} \begin{tabular}{ | l |*{3}{S|} } \Xhline{1pt} & \multicolumn{3}{c|}{Long parameter, $\alpha$ (\si{\kilo\newton\per\kilo\gram})} \ \Xcline{2-4}{0.5pt} & {$\alpha_1$} & {$\alpha_2$} & {$\alpha_3$} \ \Xhline{0.5pt} Trial A & 1.1 & 2.2 & 3.3 \ \Xhline{1pt} \end{tabular} \caption{Problem (MWE)} \end{table} \end{document}

Result is equal as before.

Zarko
  • 296,517