# How to print tabular confidence intervals as [x, y] with siunitx?

What would be the recommended way to print a confidence interval as [x, y] in an siunitx S column? At the moment I have a two S column solution:

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{table}[h]
\begin{tabular}{cS[table-format = 1.1]
S[table-format = -1.2, table-space-text-pre=[ ]@{}
S[table-format = -1.2, table-space-text-post=[, table-space-text-pre=[ ]
}
A & B & \multicolumn{2}{c}{CI} \\
Values & 2.3 & {[}1.23{,} & 1.23{]} \\
Values & 2.3 & {[}-3.42{,} & -2.43{]} \\
Values & 2.3 & {[}4.12{,} & 7.33{]} \\
Values & 2.3 & {[}-1.03{,} & -9.11{]} \\
\end{tabular}
\end{table}
\end{document}


Is there an easier siunitx way?

• Please give us some minimal working example and tell us more about the other values in that column. Do you just want intervals? Feb 8 '16 at 13:44
• Were any of the below answers a solution to your problem? If so, would you please accept an answer, so the question is marked as solved? If not, would you please leave feedback as to what the problems are?
– sodd
Feb 9 '16 at 16:25

You can make use of table-space-text-pre and table-space-text-post to make space for the square brackets. To insert the brackets before and after the columns, use the >{...} and <{...} syntax. To avoid wrong spacing before the last square bracket at each line, you have to use the TeX primitive \cr instead og \\ to terminate the rows, as explained in section 7.13 of the siunitx manual.

To center the column heading B you can simply put it in a group such as {B}.

\documentclass[border=10pt]{standalone}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{
c
S[table-format = 1.1]
>{{[}} % Add square bracket before column
S[table-format = -1.2,table-space-text-pre={[}]
@{,\,} % Add comma and thin-space between the columns
S[table-format = -1.2,table-space-text-post={]}]
<{{]}} % Add square bracket after column
}
A      & {B} & \multicolumn{2}{c}{CI} \cr
Values & 2.3 &  1.23 &  1.23 \cr
Values & 2.3 & -3.42 & -2.43 \cr
Values & 2.3 &  4.12 &  7.33 \cr
Values & 2.3 & -1.03 & -9.11 \cr
\end{tabular}
\end{document}


I try to minimise how much I type so I'd put the brackets, [ and ], into the table definition:

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{table}[h]
\begin{tabular}{cS[table-format = 1.1]
}
A      & \multicolumn{1}{c@{\quad\space}}{B} & \multicolumn{2}{c}{CI} \\
Values & 2.3 & 1.23  & 1.23 \\
Values & 2.3 & -3.42 & -2.43 \\
Values & 2.3 & 4.12  & 7.33 \\
Values & 2.3 & -1.03 & -9.11 \\
\end{tabular}
\end{table}
\end{document}


This produces:

Here I have used @{...} to insert material in between the columns. Note the sight kludge to get B in the right place. This is necessary because of the \quad, but it tends to suggest that there ought to be a more elegant solution!

• I'd advise against using the @{...} syntax to insert the brackets, as that messes with the intercolumn spacing, which you try to add "by hand". Also, the \multicolumn{1}{c... for the column heading B overwrites your manually given intercolumn spacing, thus making the cell with B wider than the rest of the cells in the column. If you add vertical lines to your table you will see this. Also, adding the last square bracket this way removes the normal spacing after the cell content, which can be seen by adding e.g. an \hline to the table.
– sodd
Feb 9 '16 at 10:18
• @Andrew the results looks good, but hooy's answer seems more compact, and I'll have to take hooy's word about the technical advantages too :) Feb 11 '16 at 4:17
• @drgibbon I agree, hooy's answer is the correct way to go. You should give him the tick.
– user30471
Feb 11 '16 at 9:06