表格中的垂直对齐

表格中的垂直对齐

我有以下代码:

\begin{table}[H]  
\begin{center}  
\caption{Quarks and leptons of the Standard Model.}  
\label{TablaQuarks}  
\begin{tabu}{|m{2cm}|m{2cm}|m{4cm}|[2pt]} \hline  
\multicolumn{3}{|c|[2pt]}{Quarks} \\ \hline  
Flavour & Charge & Mass \\ \hline  
u & 2/3 $e$ & 2.3$_{-0.5}^{+0.7}$ MeV/c$^2$ \\[1.0ex]  
d & -1/3 $e$ & 4.8$_{-0.3}^{+0.7}$ MeV/c$^2$ \\[1.0ex]\hline  
c & 2/3 $e$ & 1.275 $\pm$ 0.025 GeV/c$^2$ \\  
s &  -1/3 $e$ & 95 $\pm$ 5 MeV/c$^2$ \\ \hline  
t & 2/3 $e$ & 173.5 $\pm$ 0.6 GeV/c$^2$ \\  
b &  - 1/3 $e$ & 4.18 $\pm$ 0.03 GeV/c$^2$ \\ \hline  
\end{tabu}
\end{center}  
\end{table}

问题是我无法将文本(垂直)居中在最后一列,它始终保持在顶部。此外,垂直对齐的前两个无法水平居中。

为了使用以前的代码,您需要tabuarray包。

答案1

如果最后一列是多行条目,最好不要使用\\[length]。此版本打开表格,因此不需要,并应用于\centering单元格。我[H]从您的 MWE 中留下了,但实际上不应该需要它。

在此处输入图片描述

\documentclass{article}
\usepackage{tabu,float}
\begin{document}
\begin{table}[H]  
\begin{center}  
\caption{Quarks and leptons of the Standard Model.} 
\smallskip
\label{TablaQuarks}  
\setlength\extrarowheight{5pt}
\begin{tabu}{
|>{\centering}m{2cm}|
>{\centering}m{2cm}|
>{\centering\arraybackslash}m{4cm}|[2pt]} \hline  
\multicolumn{3}{|c|[2pt]}{Quarks} \\ \hline  
Flavour & Charge & Mass \\ \hline  
u & 2/3 $e$ & 2.3$_{-0.5}^{+0.7}$ MeV/c$^2$ \\
d & -1/3 $e$ & 4.8$_{-0.3}^{+0.7}$ MeV/c$^2$ \\\hline  
c & 2/3 $e$ & 1.275 $\pm$ 0.025 GeV/c$^2$ \\  
s &  -1/3 $e$ & 95 $\pm$ 5 MeV/c$^2$ \\ \hline  
t & 2/3 $e$ & 173.5 $\pm$ 0.6 GeV/c$^2$ \\  
b &  - 1/3 $e$ & 4.18 $\pm$ 0.03 GeV/c$^2$ \\ \hline  
\end{tabu}
\end{center}  
\end{table}

\end{document}

答案2

垂直对齐的问题是因为公式占用了太多的垂直空间,所以你需要稍微打开行。

在思考您的问题时,我决定用纯 TeX 编写我自己的表格版本,其中包括(在我看来)一些印刷方面的改进:

  • 数字和单位之间的间距

  • GeV/c^2 中 V 和 / 之间的字距

  • 不管负号如何,都将电荷置于中心,并将单位 (e) 移动到列的定义处

  • 对大部分内容使用右对齐,但列名除外,列名居中

我通过定义宏 \openline#1 插入一些垂直空间点来解决垂直间距问题。

您也可以将表格复制并粘贴到您的乳胶文档中,无需修改即可工作。

\def\hline{\noalign{\hrule}}
\def\openlineAux#1{height#1pt&\omit&\omit&\omit&height#1pt\cr}
\def\openline#1{\openlineAux#1\hline\openlineAux#1}

\vbox{\offinterlineskip
\halign{&\vrule#&\hfil#\hfil &\quad\hfil#\hfil &\quad\hfil#&\vrule#\cr
\hline\openlineAux3
&\multispan3 \hfil Quarks\hfil&\cr
\openline3
&\enskip\strut Flavour & Charge ($e$) & Mass \hfil&\cr
\openline3
&u & $\phantom{-}2/3$  & $2.3_{-0.5}^{+0.7}\; \rm MeV\!/c^2$ &\cr
\openline3
&d & $-1/3$  & $4.8_{-0.3}^{+0.7}\; \rm MeV\!/c^2$ &\cr
\openline3
&c & $\phantom{-}2/3$  & $1.275 \pm 0.025\; \rm GeV\!/c^2$ &\cr
\openline2
&s &  $-1/3$  & $95 \pm 5\; \rm MeV\!/c^2$  &\cr
\openline2
&t & $\phantom{-}2/3$  & $173.5 \pm 0.6\; \rm GeV\!/c^2$ &\cr
\openline2
&b &  $- 1/3$ & $4.18 \pm 0.03\; \rm GeV\!/c^2$ &\cr
\openlineAux2\hline
}}

在此处输入图片描述

相关内容