writing tables with statistics result often contain negative numbers in brackets, for example (-1.23)
, which should be aligned on the decimal point with other numbers in columns. this can be (simply) accomplished by S
column option parse-numbers=false
, however this option disables most of the other options of the S
column (see first example in mwe below)
another possibilities, which cross my mind is defined robust command, for example \brckt
and use it instead of (
. this approach works fine, i.e. preserve all S
column options (see the second example in mwe), however i wonder, if any one know for better solution. so far my search on this site did not yield to better solution.
the (not so) minimal working example:
\documentclass{article}
\usepackage{booktabs, threeparttable}
\usepackage{siunitx}
\usepackage{etoolbox} % used in second example
\newrobustcmd{\brckt}{(}
\begin{document}
\begin{center}
\sisetup{input-symbols = {( )}, % has no sense
table-space-text-pre={(}, % has no effect ...
table-align-text-pre=false, % has no effect ...
table-space-text-post={$^{***}$}, % has no effect ...
table-align-text-post=false, % has no effect ...
round-mode = places, % has no sense
% round-precision = 3 % make error
parse-numbers=false, % <---
}
\begin{threeparttable}[htb]
\caption{first example}
\label{tab:statistic}
\begin{tabular}{*{3}{S[table-format=-2.3]}}% integer part had to have
% one digit more than normally needed
% other vice decimal point is overwritten
\toprule
1.23\tnote{*} & 1.234 \tnote{**} & 1.2345\tnote{***} \\
(9.87) & (-7.89) & (-7.89) \\
\bottomrule
\end{tabular}
\begin{tablenotes}[para]
\item[*] text;
\item[**] text;
\item[**] text.
\end{tablenotes}
\end{threeparttable}
\end{center}
\begin{center}
\sisetup{input-symbols = {( - )},
table-space-text-pre={(},
table-align-text-pre=false,
table-space-text-post={$^{***}$},
table-align-text-post=false,
round-mode = places,
round-precision = 3
}
\begin{threeparttable}[htb]
\caption{second example}
\label{tab:statistic}
\begin{tabular}{*{3}{S[table-format=-1.3]} }
\toprule
1.23\tnote{*} & 1.234 \tnote{**} & 1.2345\tnote{***} \\
(9.87) & \brckt-7.89) & \brckt-7.89) \\
\bottomrule
\end{tabular}
\begin{tablenotes}[para]
\item[*] text;
\item[**] text;
\item[**] text.
\end{tablenotes}
\end{threeparttable}
\end{center}
\end{document}
S
column options (since they are disabled -- as expected -- byparse-numbers=false
). the problem is, how to obtain for example(-1.234)
and preserveS
column options for number formatting. not usingparse-numbers=false
cause error. in second example i try to avoid it by defining robust command for(
, but solution is somehow rude.