# Align column where each cell has two decimals with siunitx

I also want to align the second column. The problem is, that there can't be two numbers in one cell Is there a way to align the second column via digits even if there are more decimals? I also used the input-ignore option to ignore the commas

\usepackage{tabular}
\usepackage{siunitx}

\begin{document}
\begin{tabular}{@{}
S[table-format=1.2]
l
@{}}
0.30 &     [-195.728, 213.571] \\
0.000 &  [-2465.825, -1234.722] \\
0.648 &       [-35.587, 22.432] \\
\end{tabular}
\end{document}


You can split into two columns and inject the brackets:

\documentclass{article}

\usepackage{siunitx,booktabs}

\NewDocumentCommand{\lbr}{}{[\thinspace}
\NewDocumentCommand{\rbr}{}{]}

\begin{document}

\begin{tabular}{
S[table-format=1.3]
>{\lbr}S[table-format=-4.3,table-space-text-pre=\lbr]
@{, }
S[table-format=-4.3,table-space-text-post=\rbr]<{\rbr}
}
\toprule
\midrule
0.30  &  -195.728 &   213.571 \\
0.000 & -2465.825 & -1234.722 \\
0.648 &   -35.587 &    22.432 \\
\bottomrule
\end{tabular}
\end{document}


A small final note: \NewDocumentCommand is provided by xparse, which is loaded by siunitx. Using it, \lbr becomes a “protected” command, so it can be used as a “text-pre” in an S column.

• I rejected the edit adding xparse to the list of loaded packages on the grounds that I verified that the example compiles without it since siunitx already loads xparse. There might be merit in mentioning that \NewDocumentCommand is a xparse command and that siunitx loads xparse, but this should probably happen in a comment and not in an uncommented edit. – moewe Apr 24 at 13:26
• @moewe Thanks; I added a final comment with a short explanation. – egreg Apr 24 at 13:53

Split it into two columns:

\documentclass{article}

\usepackage{siunitx}

\begin{document}
\begin{tabular}{@{}
S[table-format=1.3]
@{\space[\thinspace}
S[table-format=-4.3]
@{,\space}
S[table-format=-4.3]
@{\thinspace]}
@{}}
0.30 &     -195.728 & 213.571 \\
0.000 &  -2465.825 & -1234.722 \\
0.648 &       -35.587 & 22.432 \\
\end{tabular}
\end{document}


• Rather than \space[\thinspace, use \hspace{2\tabcolsep}[\thinspace so as to restore the standard intercolumn spacing. – egreg Apr 24 at 11:27
• @egreg Thanks for your suggestion, but this would misalign the header – user186389 Apr 24 at 11:28
• Yes, you need to add the same material in \multicolumn{1}{@{}c@{\hspace*{2\tabcolsep}\phantom[\thinspace}{Radius}. Possibly better is to inject the material with >{[\thinspace} – egreg Apr 24 at 11:30
• @egreg File ended while scanning use of \multicolumn. – user186389 Apr 24 at 11:33
• @egreg >{[\thinspace} will mess with siunitx alignment – user186389 Apr 24 at 11:33

A variant layout:

\documentclass{article}

\usepackage{siunitx}

\begin{document}

\setlength{\extrarowheight}{2pt}
\begin{tabular}{@{}
S[table-format=1.3]
>{[\,}S[table-format=-4.3, table-space-text-pre = {[}, table-align-text-pre=false]<{{,}}
@{\enspace}
S[table-format=-4.3, table-space-text-post ={]}]
<{$\!$]}
@{}}