错误的多列对齐:它会随着标题的长度而变化

错误的多列对齐:它会随着标题的长度而变化

我在使用包含多列的简单表格时遇到了一个奇怪的问题。如果多列的标题足够短,则三个子列会正确对齐,否则,它们的排列会很奇怪。

这是代码和结果。提前致谢!

\documentclass[a4paper,11pt]{book}
\usepackage{caption,booktabs,multirow}
\begin{document}
\begin{table}[!h]
\centering
\begin{tabular}{ccccccc}
    \toprule
    \toprule
    \multirow{2}*{\textbf{Layer}} & \textbf{Radius} & \multirow{2}*{\#\textbf{Ladders}} & \multicolumn{3}{c}{\textbf{Sensors}} & \multirow{2}*{\textbf{APV25/Sensor}} \\
     & (mm) & & S & L & T & \\
    \midrule 
    3 & 38 & 7 & 2 & 0 & 0 & 12\\
    4 & 80 & 10 & 0 & 2 & 1 & 12\\
    5 & 115 & 12 & 0 & 3 & 1 & 12\\
    6 & 140 & 16 & 0 & 4 & 1 & 12\\
    \bottomrule
\end{tabular} 
\caption{Geometrical parameters of the SVD. S, L, and T stands for small, large, and trapezoidal sensors. The numbering scheme treats the PXD and the SVD as an only object, hence the layer numbers 1 and 2 are taken by the two PXD layers.}
\label{Belle2_SVD_Table}
\end{table}
\end{document}

在此处输入图片描述 在此处输入图片描述

答案1

只需在宽标题下为三列添加一些宽度,然后使用像这样的新列类型将它们居中即可\newcolumntype{C}{>{\centering}p{2em}}。另外,双列\toprule太重了,我只用了一个。

2em注意:中的值p{2em}是通过反复试验选择的,只有第二次猜测才是正确的。但您也可以通过以下计算获得准确的值:

\newlength\Dwidth
\settowidth{\Dwidth}{\textbf{Sensors/Ladders}}
\newcolumntype{C}{>{\centering}p{(\Dwidth-4\tabcolsep)/3}}

不过,您需要添加calc包才能执行此操作。最后,结果将与非常相似p{2em},您可能不会注意到差异。

\documentclass[a4paper,11pt]{book}
\usepackage{caption,booktabs,multirow,array}
\begin{document}

\newcolumntype{C}{>{\centering}p{2em}}

\begin{table}[!h]
\centering
\begin{tabular}{ccc*3{C}c}
    \toprule
    \multirow{2}*{\textbf{Layer}} & \textbf{Radius} & \multirow{2}*{\#\textbf{Ladders}} & \multicolumn{3}{c}{\textbf{Sensors/Ladders}} & \multirow{2}*{\textbf{APV25/Sensor}} \\
     & (mm) & & S & L & T & \\
    \midrule 
    3 & 38 & 7 & 2 & 0 & 0 & 12\\
    4 & 80 & 10 & 0 & 2 & 1 & 12\\
    5 & 115 & 12 & 0 & 3 & 1 & 12\\
    6 & 140 & 16 & 0 & 4 & 1 & 12\\
    \bottomrule
\end{tabular} 
\caption{Geometrical parameters of the SVD. S, L, and T stands for small, large, and trapezoidal sensors. The numbering scheme treats the PXD and the SVD as an only object, hence the layer numbers 1 and 2 are taken by the two PXD layers.}
\label{Belle2_SVD_Table}
\end{table}
\end{document}

在此处输入图片描述

答案2

我建议您采用一种tabularx环境来允许在最右侧的标题单元格中换行。

我还会缩短标题文字,主要是将大部分解释性材料移到表格下方的图例区域。

在此处输入图片描述

\documentclass[a4paper,11pt]{book}
\usepackage{caption,booktabs,tabularx,ragged2e}
\newcolumntype{C}{>{\Centering\arraybackslash}X}

\begin{document}
\begin{table}[!h]
\centering
\begin{tabularx}{0.8\textwidth}{@{} l CCcccC @{}}
    \toprule
    \textbf{Layer} & 
    \textbf{Radius} & \#\textbf{Ladders} & 
    \multicolumn{3}{@{}C@{}}{\textbf{Sensors\slash Ladder}} & 
    \textbf{APV25\slash Sensor} \\
    \cmidrule{4-6}
     & (mm) & & S & L & T & \\
    \midrule
    3 & 38 & 7 & 2 & 0 & 0 & 12\\
    4 & 80 & 10 & 0 & 2 & 1 & 12\\
    5 & 115 & 12 & 0 & 3 & 1 & 12\\
    6 & 140 & 16 & 0 & 4 & 1 & 12\\
    \bottomrule
\end{tabularx}

\medskip\RaggedRight\footnotesize
S, L, and T stands for small, large, and trapezoidal sensors. The numbering scheme treats the PXD and the SVD as an only object, hence the layer numbers 1 and 2 are taken by the two PXD layers.
\caption{Geometrical parameters of the SVD}
\label{Belle2_SVD_Table}
\end{table}
\end{document}

相关内容