# [Tex/LaTex] siunitx: What is the correct way to output mean and standard deviation as “M (SD)” in an S-column

rsiunitx

I am trying to use siunitx in a psychology results table to line up decimals, and the table looks like this:

\documentclass[]{article}
\begin{document}
\begin{table}[h]
\begin{tabular}{@{}cc@{}}
\multicolumn{2}{c}{Mean (SD)} \\
\hline
A & B \\
\hline
.45 (.23) & .78 (.11) \\
\end{tabular}
\end{table}
\end{document}


This does not follow the short form uncertainty that siunitx uses, rather it gives the full standard deviation value (as is usual in psychology).

My question is how can I make siunitx output to the format M (SD) whilst providing SD with an actual standard deviation value in the code (such as .11)? I cannot use the short uncertainty format of siunitx because the input is from R code (using knitr) that returns the real standard deviation value, e.g. \Sexpr{sd(some.numbers)}.

Edit: I have tried separate-uncertainty but this seems to force an output of M ± SD and I would like to use M (SD).

The formats parsed by siunitx are 1.23(4) and 1.23 \pm 0.04, and no others. Thus to achieve the desired effect some parsing has to be done separately. One approach is to grab the cell contents, alter the formatting and use the \tablenum command to do the alignment

\documentclass[]{article}
\usepackage{siunitx}
\def\converter\ignorespaces#1(#2){%
\begingroup\tablenum[table-format = 1.2]{#1}\endgroup\space
(\tablenum[table-format = 1.2]{#2})}
\newcolumntype{R}{>{\converter}c}
\begin{document}
\begin{table}[h]
\begin{tabular}{@{}RR@{}}
\multicolumn{2}{@{}c@{}}{Mean/SD} \\
.45 (.23) & .78 (.11) \\
0.2(.4) \\
\end{tabular}
\end{table}
\end{document}