Siunitx – Specifying Confidence Interval Columns with Tabularray

siunitxtabularray

When working with statistical outputs/tables, I'm curious about how to properly specify the confidence interval (CI) column with the tabularray and siunitx packages. I take this answer and replace the multicolumn command with the SetCell command, as required by the most recent tabularray package. The MWE is:

\documentclass{article}

\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{tabularray}
\UseTblrLibrary{booktabs,siunitx}

%% Need to hide parentheses from TeX by putting them inside a macro
%% more info here: https://tex.stackexchange.com/a/493771/3732
\newcommand*\bla{{(}}
\newcommand*\foo{{)}}

\begin{document}

\begin{tblr}{colspec={
      l
      S[table-format=1.2]
      >{\bla} % Add parenthesis before
      S[table-format=-1.2,table-space-text-pre={(}]
      @{,\,} % Add comma after lower limit
      S[table-format=-1.2,table-space-text-post={)}]
      <{\foo} % Add parenthesis after
    }}
  \toprule
  Variable & {{{SE}}} & \SetCell[c=2]{l}{{{95\% CI}}} &\\
  \midrule
  A & 0.02 &  0.07 & -0.08 \\
  B & 0.07 & -0.07 & -0.04 \\
  C & 0.01 &  0.05 &  0.90 \\
  \bottomrule
\end{tblr}

Result

Unfortunately, I cannot remove the leading parenthesis in the header column. Any idea?

Best Answer

Instead of adding your parenthesis to all cells of the column, you can use the cells{...}{...} option to select exactly which cells you want to add it to:

\documentclass{article}

\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{tabularray}
\UseTblrLibrary{booktabs,siunitx}

%% Need to hide parentheses from TeX by putting them inside a macro
%% more info here: https://tex.stackexchange.com/a/493771/3732
\newcommand*\bla{{(}}
\newcommand*\foo{{)}}

\begin{document}

\begin{tblr}{colspec={
      l
      S[table-format=1.2]
      S[table-format=-1.2,table-space-text-pre={(},table-space-text-post={,\,}]
      @{}
      S[table-format=-1.2,table-space-text-post={)}]
    },
    cell{2-Z}{3}={preto={\bla},appto={{,\,}}},
    cell{2-Z}{4}={appto={\foo}},
    }
  \toprule
  Variable & {{{SE}}} & \SetCell[c=2]{c} {{{95\%~CI}}} &\\
  \midrule
  A & 0.02 &  0.07 & -0.08 \\
  B & 0.07 & -0.07 & -0.04 \\
  C & 0.01 &  0.05 &  0.90 \\
  \bottomrule
\end{tblr}

\end{document}

enter image description here