1

I am struggling trying to have the four column under the multicolumn of same width and centered. This is the code:

\begin{table*}[ht]
    \centering
    \begin{tabular}{c|cccc|cc}
    \toprule
            \multirow{2}{*}{Model} & \multicolumn{4}{c|}{Percentage of predictions with error value}  &   \multirow{2}{*}{$\mu$} &   \multirow{2}{*}{$\sigma$} \\
               &   $<10\%$ &   $<5\%$  &   $<2\%$  &   $<1\%$\\
    \midrule
        Omega-Csi     &   100    &   99.95  &   98.52   &   95.77   &   -0.034  &   0.48\\
        9-Input, grid training   &   99.95    &   99.53  &   96.25   &   89.13   &   0.016  &   0.92\\
        9-Input, random training  &   100    &   99.94  &   99.51   &   97.98   &   -0.031  &   0.36\\
    \bottomrule
    \end{tabular}
    \caption{Percentage error characteristics of different model predictions on internal test sets}
    \label{tab:2}
\end{table*}

that generates this table:

enter image description here

\setlength\tabcolsep{width} doesn't work as it modifies the width of all columns and makes the table exceed the textwidth before equalizing the spaces. I would like to have all the column with the <% values of same width and occupying exactly the space under the \multicolumn header.

mcali
  • 38
  • 6
  • 2
    You might try to make the content of \multicolumn{4} use two lines with the makecell package. – Bernard Jul 05 '22 at 10:10

2 Answers2

2
  • sum of widths of the columns spanned by \multicolumn cell should be greater than width of \multicolumn content. if it is not, than last spanned column is widened accordingly
  • solution (at "classic" tables) is prescribe appropriate width of spanned columns (below in the first table), or
  • for table use tabularray package (version 2022B) with option hspan=even which take a care that spanned columns have equal widths (second table below)
  • In the second table is also used S columns defined in siunitx packages (in example loaded as tabularray library) which enable align numbers at decimal points and use math ˙-˙symbol:
\documentclass[twocolumn]{article}
\usepackage[skip=1ex, font=small, labelfont=bf]{caption}
\usepackage{multirow, tabularx}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document} \begin{table} \centering \begin{tabular}{l | {4}{>{\centering\arraybackslash} p{4em}} | cc} \toprule \multirow{2}{}{Model} & \multicolumn{4}{c|}{Percentage of predictions with error value}
& \multirow{2}{
}{$\mu$} & \multirow{2}{}{$\sigma$} \ & $<10%$ & $<5%$ & $<2%$ & $<1%$ & & \ \midrule Omega-Csi & 100 & 99.95 & 98.52 & 95.77 & -0.034 & 0.48 \ 9-Input, grid training & 99.95 & 99.53 & 96.25 & 89.13 & 0.016 & 0.92 \ 9-Input, random training & 100 & 99.94 & 99.51 & 97.98 & -0.031 & 0.36 \ \bottomrule \end{tabular} \caption{Percentage error characteristics of different model predictions on internal test sets} \label{tab:2} \end{table}

\begin{table} \caption{Percentage error characteristics of different model predictions on internal test sets} \centering \begin{tblr}{colspec = {l | Q[c, si={table-format=3.2}] {3}{Q[c, si={table-format=2.2}]} | Q[c, si={table-format=-1.3}] Q[c, si={table-format=1.2}] }, hspan = even, row{1} = {guard} } \toprule \SetCell[r=2]{c} Model & \SetCell[c=4]{c} Percentage of predictions with error value & & & & \SetCell[r=2]{c,$} \mu & \SetCell[r=2]{c,$} \sigma \ & \qty{<10}{%} & \qty{<5}{%}
& \qty{<2}{%}
& \qty{<1}{%}
& & \ \midrule Omega-Csi & 100 & 99.95 & 98.52 & 95.77 & -0.034 & 0.48 \ 9-Input, grid training & 99.95 & 99.53 & 96.25 & 89.13 & 0.016 & 0.92 \ 9-Input, random training & 100 & 99.94 & 99.51 & 97.98 & -0.031 & 0.36 \ \bottomrule \end{tblr} \end{table*} \end{document}

Note: Since in code fragment you use table* float environment, I assume that document is of two columns.

Edit: ups, forgot to add image of tables :-(. Now is presented:

enter image description here

Zarko
  • 296,517
  • First solution worked great. It is also very similar to the one I referenced in the other answer, but that uses tabularx instead – mcali Jul 06 '22 at 09:47
  • @mcali, both solution works. I prefer with tabularray because it simplicity (not need to calculate necessary spanned column widths) – Zarko Jul 06 '22 at 10:06
0

Found another post that helped me to fix the issue. It also has lots of other options for formatting differently: Table column widths disproportionate due to multicolumn cell being too long

mcali
  • 38
  • 6