使用 \multicolumn 时,我遇到列大小问题,请参见下图:
第二列的尺寸大于第一列的尺寸,应该是平衡的(与其余列一样)。
对应的latex代码:
\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}
我发现“shapes_translation”比其他标题(例如shapes_6dof)长,这导致列大小不平衡。但我不知道如何修复它。任何帮助都将不胜感激,提前谢谢。
更新:
我根据 Ben 的回答修改了代码由于多列单元格太长,导致表格列宽不成比例
\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}
然后问题解决了,但是又出现了一个问题,红色竖线不见了,我是新手,请帮忙。
答案1
新的 LaTeX3 软件包tabularray
hspan=even
有一个用于均匀分配额外空间的选项:
\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}
答案2
让我们考虑一下该表的四个版本。
现状,即当前情况(同时使表格看起来更开放,并省略最后三行数据,使外观更紧凑)。观察第二列数据过宽的情况。
表 2 与表 1 类似,但前两个数据列现在宽度相等,并且共同位于公共标题单元格下方的中心。请注意,数据列 1 和 2 明显比数据列 3 至 8 宽。
在表 3 中,我们将其缩写
shapes\_translation
为shapes\_transl.
,以使所有 8 个数据列的宽度相同。表 4 使用了(小得多的)字体大小
\emph{shapes\_translation}
,同时允许所有 8 个数据列具有相同的宽度。
精细的排版常常需要我们做出权衡。
虽然我们可以很容易地得出结论,表 1 是有问题的,表 4 也不好(因为其中一个标题单元格使用了微小的字体大小),但不清楚表 2 是否真的比表 1 好很多。为什么?
在表 2 中,我们将一个排版问题(第 2 个数据列比其他 7 个数据列宽得多)与另一个排版问题(前两个数据列的宽度明显大于其他六个数据列的宽度)进行了交换。
表 3 的折衷方案在于缩短标题单元格,这可能是最好的——或者至少是“最不坏的”——总体而言,因为它允许 8 个数据列的宽度(非常接近)相等,从而使表格具有良好平衡的“外观”。
\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}