1

I have a column size problem when using \multicolumn, please see the following pic:

enter image description here

The size of the second column is bigger than the size of the first column, which should be balanced (like the rest of the columns).

The corresponding latex code:

\begin{table}[!t]
    \renewcommand\tabcolsep{5.5pt}
    \caption{Performance}
    \begin{center}
        \begin{tabular}{|c|c|c|c|c|c|c|c|c|}
            \hline
            \multirow{2}{*}{Method} & \multicolumn{2}{c|}{\emph{shapes\_translation}} & \multicolumn{2}{c|}{\emph{shapes\_6dof}}   & \multicolumn{2}{c|}{\emph{poster\_6dof}}   & \multicolumn{2}{c|}{\emph{slider\_depth}} \\ \cline{2-9}
            & AOR                 & AR                 & AOR              & AR               & AOR              & AR               & AOR                & AR            \\ \hline
            SiamFC\cite{bertinetto2016fully}                  & 0.812             & 0.940            & 0.835          & 0.968          & 0.830          & 0.956          & 0.909            & \textbf{1.000}       \\ \hline
            ECO\cite{danelljan2017eco}                     & 0.823               & 0.943              & 0.847            & 0.969            & 0.846            & 0.960            & \textbf{0.947}              & \textbf{1.000}         \\ \hline
            SiamRPN++\cite{Li_2019_CVPR}     & 0.790             & 0.942            & 0.779          & 0.972          & 0.753          & 0.899          & 0.907            & \textbf{1.000}       \\ \hline
            ATOM\cite{Danelljan_2019_CVPR}       & 0.815             & 0.945            & 0.803          & 0.974          & 0.835          & 0.961          & 0.897            & \textbf{1.000}       \\ \hline
            E-MS\cite{barranco2018real}                  & 0.675    & 0.768   & 0.612 & 0.668 & 0.417 & 0.373 & 0.447   & 0.350  \\ \hline
            RMRNet-TS                  & 0.491    & 0.564   & 0.467 & 0.509 & 0.504 & 0.558 & 0.814   & 0.993  \\ \hline
            RMRNet                  & \textbf{0.836}    & \textbf{0.951}   & \textbf{0.866} & \textbf{0.980} & \textbf{0.859} & \textbf{0.962} & 0.915   & \textbf{1.000}  \\ \hline
        \end{tabular}
    \end{center}
\end{table}

I have found that 'shapes_translation' is longer than the other titles (such as shapes_6dof), which makes the unbalanced column size. But I do not know how to fix it. Any help will be appreciated, thank you in advance.

Update:

I have modified the code according to Ben's answer in Table column widths disproportionate due to multicolumn cell being too long

The new table and the new code: enter image description here

\newlength\widthSubTabTwo
\settowidth\widthSubTabTwo{shapes\_translation}
\newlength\lengthTwo
\setlength\lengthTwo{\dimexpr(\widthSubTabTwo+2\tabcolsep)/2-2\tabcolsep\relax}

\begin{table}[!t] \renewcommand\tabcolsep{5.5pt} \caption{Performance} \begin{center} \begin{tabular}{|c|{2}{w{c}{\lengthTwo}}|c|c|c|c|c|c|} \hline \multirow{2}{}{Method} & \multicolumn{2}{c|}{\emph{shapes_translation}} & \multicolumn{2}{c|}{\emph{shapes_6dof}} & \multicolumn{2}{c|}{\emph{poster_6dof}} & \multicolumn{2}{c|}{\emph{slider_depth}} \ \cline{2-9} & AOR & AR & AOR & AR & AOR & AR & AOR & AR \ \hline SiamFC\cite{bertinetto2016fully} & 0.812 & 0.940 & 0.835 & 0.968 & 0.830 & 0.956 & 0.909 & \textbf{1.000} \ \hline ECO\cite{danelljan2017eco} & 0.823 & 0.943 & 0.847 & 0.969 & 0.846 & 0.960 & \textbf{0.947} & \textbf{1.000} \ \hline SiamRPN++\cite{Li_2019_CVPR} & 0.790 & 0.942 & 0.779 & 0.972 & 0.753 & 0.899 & 0.907 & \textbf{1.000} \ \hline ATOM\cite{Danelljan_2019_CVPR} & 0.815 & 0.945 & 0.803 & 0.974 & 0.835 & 0.961 & 0.897 & \textbf{1.000} \ \hline E-MS\cite{barranco2018real} & 0.675 & 0.768 & 0.612 & 0.668 & 0.417 & 0.373 & 0.447 & 0.350 \ \hline RMRNet-TS & 0.491 & 0.564 & 0.467 & 0.509 & 0.504 & 0.558 & 0.814 & 0.993 \ \hline RMRNet & \textbf{0.836} & \textbf{0.951} & \textbf{0.866} & \textbf{0.980} & \textbf{0.859} & \textbf{0.962} & 0.915 & \textbf{1.000} \ \hline \end{tabular} \end{center} \end{table}

Then, the problem is solved, but I have a new problem. The red vertical line is missing. I am a newbie at this, please help.

2 Answers2

2

Let us consider four versions of the table.

  • The status quo, i.e., the current situation (while giving the table a more open "look" and leaving off the final three data rows for a more compact appearance). Observe the excessive width of 2nd data column.

  • Table 2 is similar to Table 1, but with the first two data columns now having equal width and being jointly centered below the common header cell. Note that data columns 1 and 2 are noticeably wider than data columns 3 thru 8.

  • In Table 3, we abbreviate shapes\_translation to shapes\_transl., allowing all 8 data columns to be equally wide.

  • Table 4 uses a (much) smaller font size for \emph{shapes\_translation}, also allowing all 8 data columns to be equally wide.

enter image description here

Fine typography often requires us to make trade-offs.

  • While we may readily conclude that Table 1 is problematic and Table 4 is no good (because of the minute font size used in one of the header cells), it's not clear that Table 2 is really all that much better than Table 1. Why?

  • In Table 2, we've exchanged one typographic problem (the 2nd data column being much wider than the other 7) with another one (the widths of first two data columns are noticeably larger than the widths of the other six).

  • Table 3, whose trade-off consists of abbreviating the header cell, may be best -- or, at least, "least bad" -- overall, as it allows the widths of the 8 data columns to be (very nearly) equal, giving the table a nicely balanced "look".


\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{newtxtext,newtxmath}
\usepackage{booktabs}
\usepackage{array,calc,caption}
\captionsetup{skip=0.25\baselineskip}
\newlength\mylen
\setlength\mylen{\widthof{\emph{shapes\_translation}}/2}
\begin{document}

\begin{table}[!ht]

\setlength\tabcolsep{0pt} % let LaTeX figure out optimal amount of intercolumn whitespace

\caption{Status quo: 2nd data column much wider than the other 7} \begin{tabular}{\textwidth}{@{\extracolsep{\fill}} l {8}{c} } \toprule Method & \multicolumn{2}{c}{\emph{shapes_translation}} & \multicolumn{2}{c}{\emph{shapes_6dof}} & \multicolumn{2}{c}{\emph{poster_6dof}} & \multicolumn{2}{c}{\emph{slider_depth}} \ \cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-7} \cmidrule{8-9} & AOR & AR & AOR & AR & AOR & AR & AOR & AR\ \midrule SiamFC\cite{bertinetto2016fully} & 0.812 & 0.940 & 0.835 & 0.968 & 0.830 & 0.956 & 0.909 & \textbf{1.000} \ ECO\cite{danelljan2017eco} & 0.823 & 0.943 & 0.847 & 0.969 & 0.846 & 0.960 & \textbf{0.947} & \textbf{1.000} \ SiamRPN++\cite{Li_2019_CVPR} & 0.790 & 0.942 & 0.779 & 0.972 & 0.753 & 0.899 & 0.907 & \textbf{1.000} \ ATOM\cite{Danelljan_2019_CVPR} & 0.815 & 0.945 & 0.803 & 0.974 & 0.835 & 0.961 & 0.897 & \textbf{1.000} \ %E-MS\cite{barranco2018real} & 0.675 & 0.768 & 0.612 & 0.668 & 0.417 & 0.373 & 0.447 & 0.350 \ %RMRNet-TS & 0.491 & 0.564 & 0.467 & 0.509 & 0.504 & 0.558 & 0.814 & 0.993 \ %RMRNet & \textbf{0.836}& \textbf{0.951}& \textbf{0.866}& \textbf{0.980} &\textbf{0.859} &\textbf{0.962} & 0.915 & \textbf{1.000} \
\bottomrule \end{tabular*}

\bigskip \caption{Center-set first two data columns} \begin{tabular}{1\textwidth}{@{\extracolsep{\fill}} l wc{\mylen}@{}wc{\mylen} {6}{c} } \toprule Method & \multicolumn{2}{c}{\emph{shapes_translation}} & \multicolumn{2}{c}{\emph{shapes_6dof}} & \multicolumn{2}{c}{\emph{poster_6dof}} & \multicolumn{2}{c}{\emph{slider_depth}} \ \cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-7} \cmidrule{8-9} & AOR & AR & AOR & AR & AOR & AR & AOR & AR\ \midrule SiamFC\cite{bertinetto2016fully} & 0.812 & 0.940 & 0.835 & 0.968 & 0.830 & 0.956 & 0.909 & \textbf{1.000} \ ECO\cite{danelljan2017eco} & 0.823 & 0.943 & 0.847 & 0.969 & 0.846 & 0.960 & \textbf{0.947} & \textbf{1.000} \ SiamRPN++\cite{Li_2019_CVPR} & 0.790 & 0.942 & 0.779 & 0.972 & 0.753 & 0.899 & 0.907 & \textbf{1.000} \ ATOM\cite{Danelljan_2019_CVPR} & 0.815 & 0.945 & 0.803 & 0.974 & 0.835 & 0.961 & 0.897 & \textbf{1.000} \ %E-MS\cite{barranco2018real} & 0.675 & 0.768 & 0.612 & 0.668 & 0.417 & 0.373 & 0.447 & 0.350 \ %RMRNet-TS & 0.491 & 0.564 & 0.467 & 0.509 & 0.504 & 0.558 & 0.814 & 0.993 \ %RMRNet & \textbf{0.836}& \textbf{0.951}& \textbf{0.866}& \textbf{0.980} &\textbf{0.859} &\textbf{0.962} & 0.915 & \textbf{1.000} \
\bottomrule \end{tabular*}

\bigskip \caption{Use abbreviation in header cell} \begin{tabular}{\textwidth}{@{\extracolsep{\fill}} l {8}{c} } \toprule Method & \multicolumn{2}{c}{\emph{shapes_transl.}} & \multicolumn{2}{c}{\emph{shapes_6dof}} & \multicolumn{2}{c}{\emph{poster_6dof}} & \multicolumn{2}{c}{\emph{slider_depth}} \ \cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-7} \cmidrule{8-9} & AOR & AR & AOR & AR & AOR & AR & AOR & AR\ \midrule SiamFC\cite{bertinetto2016fully} & 0.812 & 0.940 & 0.835 & 0.968 & 0.830 & 0.956 & 0.909 & \textbf{1.000} \ ECO\cite{danelljan2017eco} & 0.823 & 0.943 & 0.847 & 0.969 & 0.846 & 0.960 & \textbf{0.947} & \textbf{1.000} \ SiamRPN++\cite{Li_2019_CVPR} & 0.790 & 0.942 & 0.779 & 0.972 & 0.753 & 0.899 & 0.907 & \textbf{1.000} \ ATOM\cite{Danelljan_2019_CVPR} & 0.815 & 0.945 & 0.803 & 0.974 & 0.835 & 0.961 & 0.897 & \textbf{1.000} \ %E-MS\cite{barranco2018real} & 0.675 & 0.768 & 0.612 & 0.668 & 0.417 & 0.373 & 0.447 & 0.350 \ %RMRNet-TS & 0.491 & 0.564 & 0.467 & 0.509 & 0.504 & 0.558 & 0.814 & 0.993 \ %RMRNet & \textbf{0.836}& \textbf{0.951}& \textbf{0.866}& \textbf{0.980} &\textbf{0.859} &\textbf{0.962} & 0.915 & \textbf{1.000} \ \bottomrule \end{tabular*}

\bigskip \caption{Use a smaller font size in header cell} \begin{tabular}{1\textwidth}{@{\extracolsep{\fill}} l {8}{c} } \toprule Method & \multicolumn{2}{c}{\scriptsize\emph{shapes_translation}} & \multicolumn{2}{c}{\emph{shapes_6dof}} & \multicolumn{2}{c}{\emph{poster_6dof}} & \multicolumn{2}{c}{\emph{slider_depth}} \ \cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-7} \cmidrule{8-9} & AOR & AR & AOR & AR & AOR & AR & AOR & AR\ \midrule SiamFC\cite{bertinetto2016fully} & 0.812 & 0.940 & 0.835 & 0.968 & 0.830 & 0.956 & 0.909 & \textbf{1.000} \ ECO\cite{danelljan2017eco} & 0.823 & 0.943 & 0.847 & 0.969 & 0.846 & 0.960 & \textbf{0.947} & \textbf{1.000} \ SiamRPN++\cite{Li_2019_CVPR} & 0.790 & 0.942 & 0.779 & 0.972 & 0.753 & 0.899 & 0.907 & \textbf{1.000} \ ATOM\cite{Danelljan_2019_CVPR} & 0.815 & 0.945 & 0.803 & 0.974 & 0.835 & 0.961 & 0.897 & \textbf{1.000} \ %E-MS\cite{barranco2018real} & 0.675 & 0.768 & 0.612 & 0.668 & 0.417 & 0.373 & 0.447 & 0.350 \ %RMRNet-TS & 0.491 & 0.564 & 0.467 & 0.509 & 0.504 & 0.558 & 0.814 & 0.993 \ %RMRNet & \textbf{0.836}& \textbf{0.951}& \textbf{0.866}& \textbf{0.980} &\textbf{0.859} &\textbf{0.962} & 0.915 & \textbf{1.000} \ \bottomrule \end{tabular*}

\end{table} \end{document}

Mico
  • 506,678
  • Sincerely Thanks! I have learned a lot from you. I finally choose the 'tabularray' package to solve the question for its convenience. – xueyinhualuo Aug 22 '21 at 12:33
1

The new LaTeX3 package tabularray has an option hspan=even for distributing extra space evenly:

\documentclass{article}

\usepackage{tabularray} \usepackage{caption}

\begin{document}

\begin{table}[!t] \centering \caption{Performance} \begin{tblr}{ colspec = |c|c|c|c|c|c|c|c|c|, cell{1}{1} = {r=2}{c}, % multirow cell{1}{even} = {c=2}{c}, % multicolumn hspan = even, % distribute extra space evenly colsep = 5.5pt, } \hline Method & \emph{shapes_translation} & & \emph{shapes_6dof} & & \emph{poster_6dof} & & \emph{slider_depth} & \ \cline{2-9} & AOR & AR & AOR & AR & AOR & AR & AOR & AR \ \hline SiamFC\cite{bertinetto2016fully} & 0.812 & 0.940 & 0.835 & 0.968 & 0.830 & 0.956 & 0.909 & \textbf{1.000} \ \hline ECO\cite{danelljan2017eco} & 0.823 & 0.943 & 0.847 & 0.969 & 0.846 & 0.960 & \textbf{0.947} & \textbf{1.000} \ \hline SiamRPN++\cite{Li_2019_CVPR} & 0.790 & 0.942 & 0.779 & 0.972 & 0.753 & 0.899 & 0.907 & \textbf{1.000} \ \hline ATOM\cite{Danelljan_2019_CVPR} & 0.815 & 0.945 & 0.803 & 0.974 & 0.835 & 0.961 & 0.897 & \textbf{1.000} \ \hline E-MS\cite{barranco2018real} & 0.675 & 0.768 & 0.612 & 0.668 & 0.417 & 0.373 & 0.447 & 0.350 \ \hline RMRNet-TS & 0.491 & 0.564 & 0.467 & 0.509 & 0.504 & 0.558 & 0.814 & 0.993 \ \hline RMRNet & \textbf{0.836} & \textbf{0.951} & \textbf{0.866} & \textbf{0.980} & \textbf{0.859} & \textbf{0.962} & 0.915 & \textbf{1.000} \ \hline \end{tblr} \end{table}

\end{document}

enter image description here

L.J.R.
  • 10,932
  • Thanks for your answer. I am preparing my thesis. I have tried the package. It seems that the template does not support LaTeX3. – xueyinhualuo Aug 22 '21 at 11:52
  • @xueyinhualuo LaTeX3 is already there. You only need to update your TeXlive or MikTeX to the latest and add \usepackage{tabularray} to your document. – L.J.R. Aug 22 '21 at 12:00
  • I got several errors and warnings (such as File `ninecolors.sty' not found. \begin{document}) after I put '\usepackage{tabularray}' into my template. I have correctly installed the package and TexLive 2021 is used. – xueyinhualuo Aug 22 '21 at 12:11
  • You also need to install ninecolors package. – L.J.R. Aug 22 '21 at 12:14
  • It works! Thanks! – xueyinhualuo Aug 22 '21 at 12:26