0

How to align numbers according to \pm but not according to the points? Each row should also have a different number of decimal places.

\documentclass{article}
\usepackage{siunitx}


\begin{document}
\begin{table}
\caption{}
\centering
\small
\sisetup{separate-uncertainty}
\begin{tabular}{lS[table-format = 5.4(1)]}
\hline\hline\noalign{\smallskip}
Parameter & Value \\
\noalign{\smallskip}\hline\noalign{\smallskip} 
A   & 26.5 \pm 2.0      \\
B   & 11.102 \pm 1.2 \\
C   & 53839  \pm 550 \\
D   & 0.5863     \pm 0.016 \\

\noalign{\smallskip}\hline\noalign{\smallskip}
\end{tabular}
\end{table}

\end{document}

enter image description here

6
  • Unrelated: \pm needs to be in math mode. Oct 10, 2022 at 9:48
  • However, it is not necessary when it is a separation sign that should be aligned (siunitx package).
    – Elena Greg
    Oct 10, 2022 at 9:56
  • I think, in order to make separate-uncertainty work, you also need to set a table-format such as table-format = 5.4(1). Oct 10, 2022 at 10:41
  • Possibly a duplicate tex.stackexchange.com/questions/85769/…
    – Celdor
    Oct 10, 2022 at 10:42
  • When I set the table format, it is aligned according to the decimal points as well. Same in the possible duplicate. I need to ignore decimal places.
    – Elena Greg
    Oct 10, 2022 at 10:48

2 Answers 2

2

As this answer suggests, the S column provided by the package siunitx only comes with certain alignment functions that primarily adjust numbers to the decimal separator, which is not what you want.

I therefore would suggest that you adjust the nice answer linked above and do the alignment manually without the use of the siunitx package. Since I don't know how you wish to align the numbers behind the \pm sign, I provide below two alternative solutions. I would also suggest to have a look at the booktabs package:

\documentclass{article}
%\usepackage{siunitx}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{ l r @{\,\( \pm \)\,} r }
\toprule
{Parameter} & \multicolumn{2}{c}{Value} \\
\midrule
A   & 26.5   & 2.0   \\
B   & 11.102 & 1.2   \\
C   & 53839  & 550   \\
D   & 0.5863 & 0.016 \\
\bottomrule
\end{tabular}

\bigskip

\begin{tabular}{ l r @{\,\( \pm \)\,} l }
\toprule
{Parameter} & \multicolumn{2}{c}{Value} \\
\midrule
A   & 26.5   & 2.0   \\
B   & 11.102 & 1.2   \\
C   & 53839  & 550   \\
D   & 0.5863 & 0.016 \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

1

I am not aware of siunitx having implemented any feature to centre numbers around uncertainty markers. Perhaps it has and I don't know about it. The only workaround I can think of is to split numbers in two columns to get the effect. You could still use siunitx to let's say round numbers to some decimal places. Other than that, siunitx is not required

enter image description here

\documentclass{article}
\usepackage{siunitx}
\newcommand\ustrut{\rule{0pt}{12pt}}
\newcommand\lstrut{\rule[-6pt]{0pt}{12pt}}


\begin{document}
\begin{table}
  \sisetup{
    round-mode=figures,
    round-precision=3,
    table-alignment-mode=none,
    separate-uncertainty,
  }
  \caption{}
  \centering
  \small
  \begin{tabular}{
      l
      S[table-number-alignment=right]
      @{\(\;\pm\;\)}
      S[table-number-alignment=left]
    }
    \hline\hline
    \ustrut Parameter & \multicolumn{2}{c}{Value\lstrut}\\
    \hline\ustrut
    A   &   26.5 & 2.0 \\
    B   & 11.102 & 1.2 \\
    C   &  53839 & 550 \\
    D   & 0.5863 & 0.016 \lstrut \\
    \hline
  \end{tabular}
  \end{table}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .