将表格中带括号的部分的小数对齐

将表格中带括号的部分的小数对齐

我想创建下表,并且有以下几个问题:

在表格中,我希望将“观测值”上方的小数对齐,包括括号中的数字和 ,***同时希望 R^2 和观测值位于中间(不与小数对齐)。有什么有效的方法可以实现吗?

\begin{table}[h] \centering
\sisetup{input-symbols = {( )}}
\captionsetup{font=tenpt}
   \caption{Example table}
\begin{tabular}{@{}l *{5}{S[table-format = +5.5]}@{}}
\toprule
Groups & {15-30}  & {31-50} & {31-59}  & {50-15} & {$\geq$ 15} \\
\hline


Tea  & 0.10 & 0.50  & 0.10 & 0.60  & 0.60 \\
  & (511.32) & (966.51) & (363.02) & (61.60) & (15.11)  \\ 
Apple & 3,521.20^{***} & 2,560.61^{**} & 116.15 & 212.01^{***} & -53.20^{**} \\
  & (511.95) & (661.61) & (352.02) & (16.59) & (13.55)   \\ 
 \multirow{2}{2.2cm}{Tea \times Apple} & -1,936.55^{***} & -1,095.05 & -522.16  & 21.15 & -22.15 \\ 
   & (562.56) & (1,256.15)  & (563.16) & (91.61) & (19.15)  \\

\hline 
Observations & 566 & 566 & 566 & 566  & 566  \\

$R^{2}$ & 0.01 & 0.01 & 0.03 & 0.05 &0.03  \\
\bottomrule 
\end{tabular}
\end{table}

下表是我在 Overleaf 中得到的版本,带有警告“在第 xxx 行检测到过满的 \hbox(太宽 4.23pt)...”:

结果

答案1

在此处输入图片描述

\documentclass{article}
\usepackage{geometry}
\usepackage{siunitx}
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\sisetup{group-separator={,}, 
         input-open-uncertainty = ,
         input-close-uncertainty = ,
         table-align-text-pre = false,
         table-align-text-post = false,
         group-minimum-digits=4}
%\captionsetup{font=tenpt}
\caption{Example table}
\begin{tabular}{@{}l *{5}{S[table-format = -4.2, table-space-text-post=$^{***}$]}@{}}
\toprule
Groups & {15--30}  & {31--50} & {31--59}  & {50--15} & {$\geq$ 15} \\
\midrule


Tea                & 0.10             & 0.50           & 0.10     & 0.60           & 0.60         \\
                   & (511.32)         & (966.51)       & (363.02) & (61.60)        & (15.11)      \\
\addlinespace 
Apple              & 3521.20$^{***}$  & 2560.61$^{**}$ & 116.15   & 212.01$^{***}$ & -53.20$^{**}$ \\
                   & (511.95)         & (661.61)       & (352.02) & (16.59)        & (13.55)       \\ 
\addlinespace 
Tea $\times$ Apple & -1936.55$^{***}$ & -1095.05       & -522.16  & 21.15          & -22.15        \\ 
                   & (562.56)         & (1256.15)      & (563.16) & (91.61)        & (19.15)       \\
\midrule 
Observations       & {566}            & {566}          & {566}    & {566}          & {566}         \\
$R^{2}$            & {0.01}           & {0.01}         & {0.03}   & {0.05}         & {0.03}        \\
\bottomrule 
\end{tabular}
\end{table}

\end{document}

siunitx下面的代码应该可以与overleaf 当前使用的旧版本兼容:

\documentclass{article}
\usepackage{geometry}
\usepackage{siunitx}
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\sisetup{group-separator={,}, 
         input-open-uncertainty = ,
         input-close-uncertainty = ,
         table-align-text-pre = false,
         table-align-text-post = false,
         group-minimum-digits=4, 
         table-space-text-pre ={(},
         table-space-text-post={$^{***}$}}
%\captionsetup{font=tenpt}
\caption{Example table}
\begin{tabular}{@{}l *{5}{S[table-format = -4.2]}@{}}
\toprule
Groups & {15--30}  & {31--50} & {31--59}  & {50--15} & {$\geq$ 15} \\
\midrule


Tea                & 0.10             & 0.50           & 0.10     & 0.60           & 0.60         \\
                   & ( 511.32)         & (966.51)       & (363.02) & (61.60)        & (15.11)      \\
\addlinespace 
Apple              & 3521.20$^{***}$  & 2560.61$^{**}$ & 116.15   & 212.01$^{***}$ & -53.20$^{**}$ \\
                   & (511.95)         & (661.61)       & (352.02) & (16.59)        & (13.55)       \\ 
\addlinespace 
Tea $\times$       & -1936.55$^{***}$ & -1095.05       & -522.16  & 21.15          & -22.15        \\ 
Apple              & (562.56)         & (1256.15)      & (563.16) & (91.61)        & (19.15)       \\
\midrule 
Observations       & {566}            & {566}          & {566}    & {566}          & {566}         \\
$R^{2}$            & {0.01}           & {0.01}         & {0.03}   & {0.05}         & {0.03}        \\
\bottomrule 
\end{tabular}
\end{table}

\end{document}

相关内容