我正在使用 tabularx 创建下表,我想知道为什么第三行的 +- 号没有正确对齐,以及如何使加号和减号与数字之间的间距相等(例如,第四行的间距较小)?也许可以使用 siunitx 包?
\documentclass[12pt, twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{booktabs, multicol, multirow, longtable, tabularx, makecell}
\newcolumntype{Z}{ >{\centering\arraybackslash}X }
\begin{document}
\begin{table}[!h]
\setlength\tabcolsep{10pt}
\centering
\caption{Some test data}
\begin{tabularx}{\textwidth}{Xccc} %{X*{3}{Z}}
\toprule
\thead{Scenario} & \thead{$\Delta V$} & \thead{$B_{geod.}$} & \thead{$B_{a (geod.)}$} \\
\midrule
dh\textsubscript{1900-2000} & $-471136458\pm752053$ & -16.57$\pm$1.12 & -0.41$\pm$0.03 \\
Testrun 1 & $-410517206\pm688309$ & -17.33$\pm$ 1.16 & -0.43$\pm$0.03 \\
\midrule
Testrun 2 & $-439038086\pm779176$ & -16.55$\pm$0.99 & -0.37$\pm$0.03 \\
Testrun 3 & $-439718460\pm770058$ & -14.72$\pm$1.00 & -0.36$\pm$0.03 \\
\bottomrule
\end{tabularx}
\label{tab:some example table}%
\end{table}
\end{document}
答案1
对于这样的表格我建议siunitx
:
\documentclass[12pt, twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{booktabs,siunitx,amsmath,caption}
\sisetup{separate-uncertainty}
\begin{document}
\begin{table}[!htp]
\centering
\setlength\tabcolsep{0pt}
\caption{Some test data}
\label{tab:some example table}
\begin{tabular*}{\textwidth}{
@{\extracolsep{\fill}}
l
S[table-format=-9.0(6)]
S[table-format=-2.2(3)]
S[table-format=-1.2(1)]
@{}
}
\toprule
Scenario & {$\Delta V$} & {$B_{\textup{geod.}}$} & {$B_{\textup{a (geod.)}}$} \\
\midrule
dh\textsubscript{1900-2000} & -471136458\pm752053 & -16.57\pm 1.12 & -0.41\pm 0.03 \\
Testrun 1 & -410517206\pm688309 & -17.33\pm 1.16 & -0.43\pm 0.03 \\
\midrule
Testrun 2 & -439038086\pm779176 & -16.55\pm 0.99 & -0.37\pm 0.03 \\
Testrun 3 & -439718460\pm770058 & -14.72\pm 1.00 & -0.36\pm 0.03 \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}
除了良好的对齐之外,还有其他优点;例如,省略该separate-uncertainty
选项,表格将按如下方式排版,而输入不会发生变化。