我正在尝试制作包含数字和标准差的表格,如何正确对齐数字?数字和标准差之间的间距太大,数字与点不对齐。
感谢大家的支持!
\documentclass[12pt,a4paper]{book}
\usepackage{amsmath} % Advanced math typesetting
\usepackage{amstext}
\usepackage[utf8]{inputenc} % Unicode support (Umlauts etc.)
\usepackage[english]{babel} % Change hyphenation rules
\usepackage{hyperref} % Add a link to your document
\usepackage{url}
\usepackage{graphicx} % Add pictures to your document
\usepackage{listings} % Source code formatting and highlighting
\usepackage[per-mode=symbol]{siunitx} % for typesetting scientific units
\DeclareSIUnit\tex{TEX}
\DeclareSIUnit\ends{ends}
\DeclareSIUnit\rpm{rpm}
\DeclareSIUnit\wtp{wt\%}
\usepackage{booktabs}
\usepackage{array}
\usepackage{tabularx}
\usepackage{dcolumn}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table}
\setlength\tabcolsep{4pt}
\begin{tabularx}{\textwidth}{@{} l YYYYY @{}}
\toprule
& \multicolumn{1}{c}{\textbf{Length}} & \multicolumn{2}{c}{\textbf{Width}} & \multicolumn{2}{c}{\textbf{Thickness}} \\
\cmidrule(lr){2-6}
\textbf{Test} & [\si{\mm}] & \multicolumn{2}{c}{[\si{\mm}]} & \multicolumn{2}{c}{[\si{\mm}]} \\
\midrule
\textbf{Quasi-Static \& Fatigue}& $\approx$ \num{200} & \num{24.90} & $\pm$ \num{0.20} & \num{1.95} & $\pm$ \num{0.07} \\
\textbf{Short Beam} & $\approx$ \num{20} & \num{4.99} & $\pm$ \num{0.05} & \num{2.00} & $\pm$ \num{0.07} \\
\textbf{Impact} & $\approx$ \num{65} & \num{13.48} & $\pm$ \num{0.21} & \num{1.95} & $\pm$ \num{0.11} \\
\bottomrule
\end{tabularx}
\caption{Measured dimension with standard deviation of specimens.}\label{tab:spec_meas}
\end{table}
\end{document}
答案1
要使用表格对齐siunitx
,请执行不是将数字放在里面\num
,但直接放在S
-type 列中。在这里,我可能会选择类似
\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\sisetup{separate-uncertainty}
\begin{tabular}
{@{}
l
>{\approx}S[table-format = \approx3]
S[table-format = 2.2(2)]
S[table-format = 1.2(2)]
@{}}
\toprule
& \multicolumn{3}{c}{Dimensions/\si{mm}} \\
& \multicolumn{1}{c}{Length} & {Width} & {Thickness} \\
\midrule
Quasi-static \& fatigue & 200 & 24.90(20) & 1.95(7) \\
Short beam & 20 & 4.99(5) & 2.00(7) \\
Impact & 65 & 13.48(21) & 1.95(11) \\
\bottomrule
\end{tabular}
\end{document}
(我把各个单位合并到一个地方,因为重复看起来是多余的,但这当然取决于你。)请注意,我已将 放入\approx
表头,因此对于Length
标题,我需要\multicolumn
以避免出现杂散的!