Siunitx 右括号前的表空间

Siunitx 右括号前的表空间

我遇到了一个问题siunitx,即在每个单元格的小数点和右括号之间添加了一个空格。建议的修复方法这里对我来说没用。下面包含一个 MWE,以及一个识别该问题的屏幕截图。

我认为这\sisetup{}是我的错。

\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}

在此处输入图片描述

答案1

我无法重现您的问题。括号内的数字相近。不过,我会稍微改变一下您的表格设计:

  • 我不会用adjustbox
  • \cmidrule我会放在multicolumn单元格下面
  • 在 MWE 中,我会缩短\sisetup为仅必要的选项,但删除的行不会影响结果。
\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}

在此处输入图片描述

答案2

我也无法重现您遇到的间距问题。(我使用 MacTeX2019。)无论如何,我的主要建议是不是adjustbox根本不要使用该包。相反,请使用将tabular*整体宽度设置为 的普通环境\textwidth。以下代码和屏幕截图中的上表显示了如何实现这一点。

对于手头的表格,我认为将其宽度设置为 并不是一个特别好的想法\textwidth。相反,只需按其自然宽度排版表格即可创建美观紧凑的“外观”,如下面第二个表格所示。

在此处输入图片描述

\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}

相关内容