Last column in table under \multicolumn is of different width

tablestabularx

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.

Best Answer

  • 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

Related Question