I'm trying to make this table with numbers and standard deviation, how can I aligns the numbers properly?
The spacing between numbers and st.dev is too high and the numbers are not aligned to the point.
Thanks to all for support!
\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}
Best Answer
To get table alignment using
siunitx
, do not put the numbers inside\num
but just straight inside anS
-type column. Here, I'd probably go for something like(I've combined the units into one place as the repeats seems superfluous, but that's of course down to you.) Notice that I've put the
\approx
into the table header, so for theLength
heading I need a\multicolumn
to avoid a stray one!