4

I am creating the following table below with tabularx and I was wondering why the +- sign do not align correctly in the third row and how could I reach an equal separation between the plus and minus sign and numbers (e.g. in the fourth row the spacing is smaller)? Maybe by using siunitx package?

enter image description here

\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}
  • 4
    That is probably due to the ‘proportional’ digits: all digits do not have exactly the same width. You should use the S column type from siunitx, which would also turn your hyphens to a true minus sign, and avoid having to type all those $$. – Bernard Jan 8 '18 at 9:42
  • 3
    Maybe by using siunitx package? Yes, use S column type (as mentioned above) for instant magic. – Oleg Lobachev Jan 8 '18 at 9:46
  • 1
    There is a white space in -17.33$\pm$ 1.16 There is no white space in the other rows. Could this be the problem? – Stefan Jan 8 '18 at 15:14
10

For such tables I'd recommend 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}

enter image description here

Apart from good alignment, there are other advantages; for instance, omitting the separate-uncertainty option, the table would be typeset as follows, with no change in the input.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.