4

I am observing strange behaviour in which toprule, midrule, bottomrule fail to extend until the last columns of my table.

In the MWE below, I reproduce the issue using toprule, & bottomrule

%%% Using MDPI journal template %%%
\begin{table}[!htbp]
    \caption{My Table title} \label{tab1}
    \begin{adjustwidth}{-\extralength}{0cm}
    \centering
    \begin{tabularx}{\textwidth}{@{} ll *{10}{c}}
    \toprule
    &  & \multicolumn{2}{c}{Experiment 1} & \multicolumn{2}{c}{Experiment 2} & \multicolumn{2}{c}{Experiment 3} & \multicolumn{2}{c}{Experiment 4}  & \multicolumn{2}{c}{Experiment 5} \\
    \cmidrule(r{1ex}){3-4} \cmidrule(r{1ex}){5-6} \cmidrule(r{1ex}){7-8} \cmidrule(r{1ex}){9-10} \cmidrule(r{1ex}){11-12}
    && {ABC} & {XYZ} & {ABC} & {XYZ} & {ABC} & {XYZ} & {ABC} & {XYZ} & {ABC} & {XYZ} \\
    %\midrule
    \cmidrule{1-12} %\cmidrule(lr{1em}){1-12}
   \multirow{ 3}{*}{Group 1} 
       & \textit{First Round}  & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\
       & \textit{Second  Round}  & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\
       & \textit{Last  Round}  & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\  
    \bottomrule     
    \end{tabularx}
    \end{adjustwidth}
\end{table} 

Output:

enter image description here

1
  • 1
    Please post a complete MWE including your preamble.
    – Mane32
    Sep 20 at 17:52

5 Answers 5

4

You're attempting to use a tabularx environment but don't assign the X column type to any one of the 12 columns. You cannot possibly succeed in achieving the table's target width, viz., \textwidth.

Since line-breaking within cells -- which is what's enabled by the X column type -- does not appear to be a meaningful activity for the table at hand, I suggest you employ a tabular* environment instead and reorganize the headers in order to save a lot of (horizontal) space. I.e., something like this:

enter image description here

Observe that with this setup, there's no need to resort to the adjustwidth sledgehammer.

\documentclass{article}
\usepackage{booktabs}
\newcommand\mcii[1]{\multicolumn{2}{c}{#1}} % handy shortcut macro

\begin{document} 
\begin{table}[!htbp]
    \setlength\tabcolsep{0pt}
    \caption{My table title\strut} \label{tab1}
    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} ll *{10}{c} }
    \toprule
    Group & Round & \multicolumn{10}{c}{Experiments} \\
    \cmidrule{3-12}
    & & \mcii{1} & \mcii{2} & \mcii{3} & \mcii{4} & \mcii{5} \\
    \cmidrule{3-4} \cmidrule{5-6} \cmidrule{7-8} \cmidrule{9-10} \cmidrule{11-12} 
    & & ABC & XYZ & ABC & XYZ & ABC & XYZ & ABC & XYZ & ABC & XYZ \\ 
    \midrule 
    1 & First  & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\
      & Second & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\
      & Last   & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\  
    \bottomrule     
    \end{tabular*}
\end{table} 
\end{document}
2

Using tabularx without an X-column doesn't make much sense. It's also the cause of the lines not drawing along the full table (you inherently restrict the tabular width to the first argument provided to tabularx).

The solution is to drop tabularx for this construction, and just set it as a regular tabular:

enter image description here

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{table}
  \caption{My Table title}
  \begin{tabular}{@{} ll *{10}{c}}
    \toprule
    & & 
      \multicolumn{2}{c}{Experiment 1} & 
      \multicolumn{2}{c}{Experiment 2} & 
      \multicolumn{2}{c}{Experiment 3} & 
      \multicolumn{2}{c}{Experiment 4} & 
      \multicolumn{2}{c}{Experiment 5} \\
    \cmidrule(r{1ex}){3-4} 
      \cmidrule(r{1ex}){5-6} 
      \cmidrule(r{1ex}){7-8} 
      \cmidrule(r{1ex}){9-10} 
      \cmidrule(r{1ex}){11-12}
      &                       & ABC  & XYZ  & ABC  & XYZ  & ABC  & XYZ  & ABC  & XYZ  & ABC  & XYZ  \\
    \midrule
            & \textit{First Round}  & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\
    Group 1 & \textit{Second Round} & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\
            & \textit{Last Round}   & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\  
    \bottomrule     
  \end{tabular}
\end{table} 

\end{document}
2
  • Judging by the position of the caption, the width of the tabular environment would appear to exceed \textwidth by a considerable margin [pun intended].
    – Mico
    Sep 20 at 18:08
  • 1
    @Mico: Indeed! The OP uses adjustwidth from changepage to circumvent this somewhat, but that wasn't part of the question.
    – Werner
    Sep 20 at 18:13
1

For completeness, version with use of the tabularray package:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
    \begin{table}[ht]
\caption{My table title\strut} 
\label{tab1}
    \begin{tblr}{colsep=3pt,
                 colspec = {@{} lQ[l, font=\itshape] *{10}{X[c]} @{}},
                 cell{1}{3} = {c=10}{c},
                 cell{1}{1,2} = {r=3}{h},
                 cell{2}{odd[3]} = {c=2}{}
                 }
    \toprule
        & Round &   Experiments
                    &   &   &   &   &   &   &   &   &   \\
    \cmidrule{3-12}
        &       & 1 &   & 2 &   & 3 &   & 4 &   & 5 &   \\
    \cmidrule[lr]{3-4} \cmidrule[lr]{5-6} \cmidrule[lr]{7-8} \cmidrule[lr]{9-10} \cmidrule[lr]{11-12}
        &       & ABC   & XYZ   & ABC   & XYZ   & ABC   & XYZ   & ABC   & XYZ   & ABC   & XYZ \\
    \midrule
        & First & 0.87  & 0.67  & 0.50  & 0.61  & 0.47  & 0.58  & 0.49  & 0.50  & 0.41  & 0.52 \\
Group 1 & Second& 0.87  & 0.67  & 0.50  & 0.61  & 0.47  & 0.58  & 0.49  & 0.50  & 0.41  & 0.52 \\
        & Last  & 0.87  & 0.67  & 0.50  & 0.61  & 0.47  & 0.58  & 0.49  & 0.50  & 0.41  & 0.52 \\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

enter image description here

1

Besides the good answers about the latex code, what about the content design?

As far as I can guess, "Group 1 column" could have more sense in the table caption, or as header of the "Rounds" column.

On the other hand, especially if the table is for a two-column document (that could be not your case, being an example of why you should always show a MWE, not just the table), instead of showing data in a 10 x 3 array, why not in a 3x10? i.e., transposing the table. Just an example (MWE), probably not useful for you, but maybe for someone else fitting a table in narrow columns:


mwe


\documentclass[twocolumn]{article}
\usepackage{booktabs,multirow,lipsum}
\setlength{\belowcaptionskip}{1ex plus 0.1ex minus .ex}
\begin{document} 
\lipsum[1][1-5]
\begin{table}[!htbp]
\def\abc{$\left\{\begin{array}{c} \mbox{ABC} \\ \mbox{XYZ} \\\end{array}\right.$}
\centering
\caption{My table title} 
\begin{tabular}{ccccc} \toprule
&  \multicolumn{3}{c}{Rounds Group 1} \\\cmidrule{2-4}
Experiment & First & Second & Last \\\midrule       
\multirow{2}{*}{1 \abc} & 0.00 & 0.00 & 0.00 \\ 
  & 0.00 & 0.00 & 0.00 \\\addlinespace  
\multirow{2}{*}{2 \abc} & 0.00 & 0.00 & 0.00 \\ 
  & 0.00 & 0.00 & 0.00 \\\addlinespace  
\multirow{2}{*}{3 \abc} & 0.00 & 0.00 & 0.00 \\ 
  & 0.00 & 0.00 & 0.00 \\\addlinespace  
\multirow{2}{*}{4 \abc} & 0.00 & 0.00 & 0.00 \\ 
  & 0.00 & 0.00 & 0.00 \\\addlinespace  
\multirow{2}{*}{5 \abc} & 0.00 & 0.00 & 0.00 \\ 
  & 0.00 & 0.00 & 0.00 \\
\bottomrule     
\end{tabular}
\end{table} 
\lipsum[2-5]
\end{document}
0

Note that tabularx needs at least one X column, but there's no real use for it.

Repetitions should be avoided as much as possible in tables, here the (long) word “Experiment”: a further header makes the table more compact.

Also reserving a column for the group wastes precious space.

\documentclass{article}
\usepackage{booktabs,siunitx,caption}

\begin{document}

\begin{table}[!htbp]

\caption{My Table title} \label{tab1}

\setlength{\tabcolsep}{0pt}

\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l
  *{10}{S[table-format=1.2]}
}
\toprule
& \multicolumn{10}{c}{Experiment} \\
\cmidrule{2-11}
& \multicolumn{2}{c}{1}
& \multicolumn{2}{c}{2}
& \multicolumn{2}{c}{3}
& \multicolumn{2}{c}{4}
& \multicolumn{2}{c}{5} \\
\cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-7} \cmidrule{8-9} \cmidrule{10-11}
& {ABC} & {XYZ} & {ABC} & {XYZ} & {ABC} & {XYZ} & {ABC} & {XYZ} & {ABC} & {XYZ} \\
\midrule
\multicolumn{11}{l}{\itshape Group 1} \\
First Round  & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\
Second Round & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\
Last  Round  & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\  
\midrule
\multicolumn{11}{l}{\itshape Group 2} \\
First Round  & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\
Second Round & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\
Last  Round  & 0.87 & 0.67 & 0.50 & 0.61 & 0.47 & 0.58 & 0.49 & 0.50 & 0.41 & 0.52 \\  
\bottomrule
\end{tabular*}

\end{table} 

\end{document}

enter image description here

If you have just one group per table, put “Group 1” in the header's first column, to the left of “Experiment”.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .