[Tex/LaTex] Table alignment around \pm sign: how to have good alignment without \pm, where appropriate

tables

First, a MWE:

\documentclass[12pt]{article}
\usepackage{parskip}
\usepackage{amsmath}
\usepackage{upgreek}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{dcolumn}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}

\begin{table}
 \caption{Table showing the measured count rates per megabecquerel of activity for each of the three windows, to three significant figures. The quoted uncertainty corresponds to one standard deviation.}\label{tab:results1} \vspace{3 mm}
  \centering
  \begin{tabular}{
  l
  S[table-format=9.0]@{\;\( \pm \)}
  S[table-format=3.0]
  }
    \toprule
    Window & \multicolumn{2}{r}{Count rate (${\mathrm{min^{-1}\cdot MBq^{-1}}}$)} \\ \midrule
    Open &  59700000 & 2700000  \\
    ${^{99}\mathrm{Tc^m}}$ &  6100000 & 270000  \\
   ${^{223}\mathrm{Ra}}$ & 35100000 & 1500000 \\
   TEST & 123000 \\
    \bottomrule
  \end{tabular}
\end{table}

\begin{table}
\begin {center}
\begin{tabular}{c D{,}{\pm}{-1} D{,}{\pm}{-1} D{,}{\pm}{4.4} }
\toprule
    Window & \multicolumn{2}{r}{Count rate (${\mathrm{min^{-1}\cdot MBq^{-1}}}$)} \\ \midrule
    Open &  59700000\, , \,2700000  \\
    ${^{99}\mathrm{Tc^m}}$ &  6100000\, , \,\;270000  \\
   ${^{223}\mathrm{Ra}}$ & 35100000\, , \,1500000 \\
   TEST & 123000  \\
\bottomrule
\end{tabular}
\caption{Summary of statistics from analysis of all three samples.}
\end {center}
\end{table}

\end{document}

My question is how to get good alignment around the \pm sign in the columns of a table, while retaining the ability to have column entries without \pm signs.

Of the two methods I use, siunitx is vastly superior (and, as I understand it, it is the recommended standard for table alignment). The dcolumn method feels kinda hacky, and the alignment is wrong (needs further hacking with the manual insertion of spaces to fix, which is inelegant and annoying).

The problem with the siunitx approach, as I now use it, is that it inserts a \pm even when I don't want one. I guess the hack here is to put zero in as the error, but that looks less elegant (footnote: this is just a toy table; in the real-life case, the number without an uncertainty is the observed (data) number of events, whereas the numbers that need uncertainties are the expected numbers of events).

Best Answer

I'd type the uncertainty in the same column

\documentclass[12pt]{article}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage[version=4]{mhchem}

\sisetup{separate-uncertainty}

\begin{document}

\begin{table}
\centering

\caption{Table showing the measured count rates per  megabecquerel
  of activity for each of the three windows, to three significant
  figures. The quoted uncertainty corresponds to one standard
  deviation.}\label{tab:results1}

\medskip

\begin{tabular}{
  l
  S[table-format=8.0(7)]
  }
\toprule
Window         & {Count rate} \\
               & {(\si{min^{-1}.MBq^{-1}})} \\
\midrule
Open           &  59700000 \pm 2700000 \\
\ce{^{99}Tc^m} &   6100000 \pm  270000 \\
\ce{^{223}Ra}  &  35100000 \pm 1500000 \\
TEST           &    123000 \\
\bottomrule
\end{tabular}

\end{table}

\end{document}

enter image description here

  1. The column header is better split into two lines, so it's not wider than the column

  2. Chemical elements can be better named with mhchem and \ce

  3. The unit of measure should be input as argument to \si

In the event a style forces you into right aligning the uncertainty, I don't think siunitx supports it, so you need some more work.

\documentclass[12pt]{article}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage[version=4]{mhchem}
\usepackage{collcell}

\begin{document}

\begin{table}
\centering

\caption{Table showing the measured count rates per  megabecquerel
  of activity for each of the three windows, to three significant
  figures. The quoted uncertainty corresponds to one standard
  deviation.}\label{tab:results1}

\medskip

\begin{tabular}{
  l
  >{\collectcell\num}r<{\endcollectcell}
  @{${}\pm{}$}
  >{\collectcell\num}r<{\endcollectcell}
}
\toprule
Window         & \multicolumn{2}{c}{Count rate} \\
               & \multicolumn{2}{c}{(\si{min^{-1}.MBq^{-1}})} \\
\midrule
Open           &  59700000 & 2700000 \\
\ce{^{99}Tc^m} &   6100000 &  270000 \\
\ce{^{223}Ra}  &  35100000 & 1500000 \\
TEST           &    \multicolumn{1}{r@{\phantom{${}\pm{}$}}}{\num{123000}} \\
\bottomrule
\end{tabular}

\end{table}

\end{document}

enter image description here