Based on my very limited knowledge of TeX (and searching the Internet) I came up with the following solution which I will provide here as a start for others to improve on this:
\documentclass{minimal}
\usepackage{siunitx}
\usepackage{stringstrings}
\newcommand*{\numRF}[2]{\num[round-mode=figures,round-precision=#2]{#1}}
\begin{document}
\newcommand{\matchroundtabular}[2]{% only works for integer values
{%
\aftergroup\round
\stringlength[q]{#1}
\newcount\numlen
\numlen=\theresult
\stringlength[q]{#2}
\newcount\errorlen
\errorlen=\theresult
\newcount\round
\round=\numlen
\advance\round by -\errorlen
\advance\round by 1
\expandafter
}
\the\round
{\numRF{#1}{\round}} & {\numRF{#2}{2}}%
}
% Problem 1: alignment off
\sisetup{round-mode = figures,round-precision = 2, table-number-alignment = right}%
\begin{tabular}{
l
S[table-format=6.0]@{$\,\pm\,$}S[table-format=3.0]@{~}
S[table-format=6.0]@{$\,\pm\,$}S[table-format=3.0]@{~}
}
2 tight $\tau$s & \matchroundtabular{72293}{269} & 80839 & 51 \\
2 medium $\tau$s & \matchroundtabular{212383}{461} & 231155 & 125 \\
\end{tabular}
% Problem 2: not working here
\begin{tabular}{c@{$\,\pm\,$}c}
Aaaaa & Bbbbb \\
\matchroundtabular{343454}{455}
\end{tabular}
\end{document}
Output:
So this works but has two problems:
- The alignment is off. (Compare with the column with 81000+-51, which is correctly aligned but not rounded correctly.)
- It does not work outside the
S
column definition. (See second table. My code is bad.)
It currently also only works for integers. (Doing the same for floats is certainly much more complicated -- and I don't need it right now.)