3

I have a problem with siunitx, such that a space is being added between the decimals and the closing parenthesis for every cell. The fix suggested here did not work for me. A MWE is included below, with a screenshot identifying the issue.

I assume my \sisetup{} is to blame.

\documentclass{article}
\usepackage{siunitx,booktabs,adjustbox} 
\begin{document}
\begin{table}[h]
 \centering
 \caption{Estimated Main Effects (Social Index)}
 \begin{adjustbox}{width = \textwidth, center}
\sisetup{
            detect-all,
            table-number-alignment = center,
            table-figures-integer = 1,
            table-figures-decimal = 3,
            table-space-text-post = ***,
            input-symbols = {()},
}
\begin{tabular}{@{\extracolsep{6pt}}r*{4}{S[table-format = <1.2, table-number-alignment = center, table-column-width=2.5cm]}}
 \toprule
 & \multicolumn{2}{c}{\textbf{Unadjusted}} & \multicolumn{2}{c}{\textbf{Adjusted}} \\
 & \multicolumn{1}{c}{\textit{Effect}} & \multicolumn{1}{c}{\textit{(SE)}} & \multicolumn{1}{c}{\textit{Effect}} & \multicolumn{1}{c}{\textit{(SE)}} \\\cmidrule{2-2}\cmidrule{3-3}\cmidrule{4-4}\cmidrule{5-5} 
 \textbf{\textit{Vars1}} &  &  &  &  \\
 Var1 & 0.107 & (0.021) & 0.106 & (0.021) \\
 \textbf{\textit{Vars2}} &  &  &  &  \\
 Var2a & -0.041 & (0.029) & -0.039 & (0.029) \\
 Var2b & -0.085 & (0.030) & -0.083 & (0.030) \\
 Var2c & -0.130 & (0.030) & -0.134 & (0.029) \\
 \bottomrule
 \end{tabular}
 \end{adjustbox}
 \end{table}
\end{document}

enter image description here

Mico
  • 506,678

2 Answers2

1

I can't reproduce your problem. Parenthesis are nearby numbers. However, I wold slightly change your table design:

  • I wouldn't use adjustbox
  • \cmidrule I would put below multicolumn cells
  • In MWE I would shortened \sisetup to only necessary options, but removed lines don't influence on result.
\documentclass{article}

\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
    \begin{table}[ht]
    \centering
\caption{Estimated Main Effects (Social Index)}
\sisetup{input-symbols = {()},
         table-format=-1.3,
         table-space-text-post={)},
        }

\begin{tabular}{r*{4}{S} }
    \toprule
    & \multicolumn{2}{c}{\textbf{Unadjusted}} & \multicolumn{2}{c}{\textbf{Adjusted}} \\
    \cmidrule(r){2-3}\cmidrule(l){4-5}
        &   {\textit{Effect}}
                &   {\textit{(SE)}}
                            &   {\textit{Effect}}
                                        &   {\textit{(SE)}}  \\
        \midrule
\textbf{\textit{Vars1}}
    &       &           &           &                       \\
Var1   & 0.107 & (0.021)   & 0.106     & (0.021)               \\
\textbf{\textit{Vars2}}
    &       &           &           &                       \\
Var2a & -0.041 & (0.029)   & -0.039    & (0.029)               \\
Var2b & -0.085 & (0.030)   & -0.083    & (0.030)               \\
Var2c & -0.130 & (0.030)   & -0.134    & (0.029)               \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

Zarko
  • 296,517
  • Strange, even this reproduces my error in my TeX. – ironchefsakai Mar 09 '20 at 00:09
  • @ironchefsakai, I tested proposed solution with yesterday updated MikTeX (which has recent siunitx from 2020/02/25). Try to update your LateX installation. It might help/solve your problem. – Zarko Mar 09 '20 at 00:13
  • Yeah, I will give that a shot—I'm on Linux Mint 19.1, so it's possible I have the wrong ppa. – ironchefsakai Mar 09 '20 at 00:18
  • I took your suggestion and installed MikTeX. Unfortunately, the issue persists. Is siunitx known to conflict with any other packages? – ironchefsakai Mar 09 '20 at 00:44
1

I am also unable to reproduce the spacing issue you've encountered. (I use MacTeX2019.) Anyway, my main suggestion is that you not use the adjustbox package at all. Instead, use a plain tabular* environment whose overall width is set to \textwidth. The following code and the upper table in the screenshot show how this may be achieved.

For the table at hand, I'd say that it's not a particularly good idea to set its width to \textwidth. Instead, just typeset the table at its natural width to create a nice and compact "look", as is illustrated in the second table shown below.

enter image description here

\documentclass{article}
\usepackage{siunitx,booktabs}
\sisetup{input-symbols = {()}}

\begin{document}
\begin{table}[h]
\centering 

\caption{Estimated Main Effects (Social Index)}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
  r *{2}{S[table-format=-1.3,
           table-space-text-post = ***] % is this needed??
         S[table-format= 1.3,
           table-space-text-pre  = (,
           table-space-text-post = )]} @{}}
 \toprule
 & \multicolumn{2}{c}{\textbf{Unadjusted}} 
 & \multicolumn{2}{c@{}}{\textbf{Adjusted}} \\
 \cmidrule{2-3} \cmidrule{4-5}
 & {\textit{Effect}} & {\textit{(SE)}} 
 & {\textit{Effect}} & {\textit{(SE)}} \\
 \cmidrule{2-5} 
 \textbf{\textit{Vars1}} \\
 Var1  &  0.107 & (0.021) & 0.106 & (0.021) \\
 \addlinespace
 \textbf{\textit{Vars2}} \\
 Var2a & -0.041 & (0.029) & -0.039 & (0.029) \\
 Var2b & -0.085 & (0.030) & -0.083 & (0.030) \\
 Var2c & -0.130 & (0.030) & -0.134 & (0.029) \\
 \bottomrule
\end{tabular*}

\bigskip
\caption{Same table, but at natural width}
\begin{tabular}{@{}
  r *{2}{S[table-format=-1.3] 
         S[table-format= 1.3,
           table-space-text-pre  = (,
           table-space-text-post = )]} @{}}
 \toprule
 & \multicolumn{2}{c}{\textbf{Unadjusted}} 
 & \multicolumn{2}{c@{}}{\textbf{Adjusted}} \\
 \cmidrule(lr){2-3} \cmidrule(l){4-5}
 & {\textit{Effect}} & {\textit{(SE)}} 
 & {\textit{Effect}} & {\textit{(SE)}} \\
 \cmidrule(l){2-5} 
 \textbf{\textit{Vars1}} \\
 Var1  &  0.107 & (0.021) & 0.106 & (0.021) \\
 \addlinespace
 \textbf{\textit{Vars2}} \\
 Var2a & -0.041 & (0.029) & -0.039 & (0.029) \\
 Var2b & -0.085 & (0.030) & -0.083 & (0.030) \\
 Var2c & -0.130 & (0.030) & -0.134 & (0.029) \\
 \bottomrule
\end{tabular}

\end{table}
\end{document}
Mico
  • 506,678