表格与 siunitx(表格格式)、esttab、星号和整数不对齐

表格与 siunitx(表格格式)、esttab、星号和整数不对齐

我使用 Stata 的 esttab 命令创建包含 t 检验结果的各种表格。在 Latex 中,我使用 siunitx 对表格进行适当的布局。但是,我无法对表格进行编码,因此它是否向右对齐。我的最后一列和表格长度之间总是有一些空白。

这是我的 MWE:

\documentclass[a4paper,11pt]{report}

\usepackage[utf8]{inputenc}
\usepackage[main=english, german, spanish]{babel}
\usepackage[T1]{fontenc} 
\usepackage{mathtools} 
\usepackage[np]{numprint} 
 \npthousandsep{,}\npthousandthpartsep{}\npdecimalsign{.} 
\usepackage{graphicx} 
\usepackage{float} 
\usepackage{array, booktabs}
\usepackage{longtable} 
\usepackage{tabularx}
\usepackage{dcolumn} 
\newcolumntype{d}[1]{D{.}{.}{#1}}
\usepackage{array,ragged2e}
\setlength{\intextsep}{8.0pt plus 1.0pt minus 1.0pt} % To change the space between figure/table [ht] and text (underneath)
\setlength{\textfloatsep}{8.0pt plus 1.0pt minus 1.0pt} % To change the space between two floats (figure/table...) and text (underneath)    
\setlength{\belowcaptionskip}{5.0pt plus 1.0pt minus 1.0pt} % To change the space below float caption
\setlength{\abovecaptionskip}{5.0pt plus 1.0pt minus 1.0pt} % To change the space below float caption


\usepackage{siunitx} 
\sisetup{
        group-digits        = false ,
        input-signs     =-+ ,
        input-symbols       = ( ) [ ] - + {*} {**} {***},
        table-align-text-post   = false, 
        table-number-alignment = center, 
        table-figures-decimal=4,
        table-figures-exponent=4
        }



\begin{document}

\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{MWE}
\begin{tabular*}{1.0\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l*{3}{S[table-format=1.3] S[table-format=3] S[table-format=1.3] S[table-format=3] S[table-format=1.3,  table-space-text-post =\sym{***}] S[table-format=1.3] S[table-format=3]}}
\toprule
            &\multicolumn{2}{c}{High ratios}&\multicolumn{2}{c}{Low ratios}&\multicolumn{3}{c}{\textit{t} test}            \\\cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-8}
            &      {Mean}&      {Obs.}&      {Mean}&      {Obs.}&     {Diff.}         &        {SE}&      {Obs.}\\
\midrule
\textit{divDm}&       0.397&         315&       0.418&         304&       0.021         &       0.040&         619\\
\textit{divRto}&       0.144&         315&       0.156&         304&       0.013         &       0.025&         619\\
\textit{divYld}&       0.012&         314&       0.012&         300&      -0.000         &       0.002&         614\\
\textit{intCov}&       3.663&         315&       7.267&         304&       3.604\sym{*}  &       1.458&         619\\
\textit{intCovAdj}&       1.433&         313&       1.687&         304&       0.254\sym{*}  &       0.111&         617\\
\textit{lvrg1}&       0.368&         315&       0.428&         306&       0.060\sym{***}&       0.015&         621\\
\textit{lvrg1Adj1}&       0.468&         315&       0.533&         304&       0.065\sym{***}&       0.013&         619\\
\textit{lvrg2}&       0.421&         315&       0.425&         306&       0.005         &       0.015&         621\\
\textit{lvrg2Adj1}&       0.511&         315&       0.517&         304&       0.006         &       0.012&         619\\
\textit{lvrg3}&       0.744&         315&       0.768&         306&       0.025         &       0.015&         621\\
\textit{lvrg3Adj1}&       0.781&         315&       0.805&         304&       0.024         &       0.013&         619\\
\textit{prfMrg}&       0.011&         315&       0.021&         306&       0.010         &       0.007&         621\\
\textit{prfMrgAdj}&       0.041&         313&       0.060&         304&       0.019\sym{**} &       0.006&         617\\
\textit{roa}&       0.016&         315&       0.030&         306&       0.014\sym{**} &       0.005&         621\\
\textit{roaAdj}&       0.026&         313&       0.039&         303&       0.013\sym{**} &       0.004&         616\\
\bottomrule
\multicolumn{8}{l}{\footnotesize * p<0.05, ** p<0.01, *** p<0.001}\\
\end{tabular*}
\end{table}

\end{document}

我猜 siunitx-setup 或我处理表格格式选项的方式一定有问题。有人能建议我如何修复代码,以便表格与表格的文本宽度/长度对齐吗?我想继续使用 esttab。

答案1

太长了,我没法评论:

  • 欢迎来到 TeX.SE!
  • 您定义了 22 列,但只使用了 8 列!
  • 你的表格很好地适合文本宽度(好吧,修复后@{\hskip\tabcolsep\extracolsep\fill}更正确@{\hspace*{\tabcolsep}\extracolsep{\fill}}
  • 所以我不知道你的问题是什么......

对您的代码做了一些小的更改后,我得到了以下结果:

\documentclass[a4paper,11pt]{report}

\usepackage[utf8]{inputenc}
\usepackage[main=english, german, spanish]{babel}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage[np]{numprint}
 \npthousandsep{,}\npthousandthpartsep{}\npdecimalsign{.}
\usepackage{graphicx}
\usepackage{float}
\usepackage{array, booktabs, longtable, tabularx}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\usepackage{ragged2e}
\setlength{\intextsep}{8.0pt plus 1.0pt minus 1.0pt} % To change the space between figure/table [ht] and text (underneath)
\setlength{\textfloatsep}{8.0pt plus 1.0pt minus 1.0pt} % To change the space between two floats (figure/table...) and text (underneath)
\setlength{\belowcaptionskip}{5.0pt plus 1.0pt minus 1.0pt} % To change the space below float caption
\setlength{\abovecaptionskip}{5.0pt plus 1.0pt minus 1.0pt} % To change the space below float caption
\usepackage{siunitx}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

\begin{table}[htbp]
\sisetup{table-align-text-post = false}
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{MWE}
\begin{tabular*}{\hsize}{@{\hspace*{\tabcolsep}\extracolsep{\fill}}
            >{\itshape}l
                S[table-format=1.3] S[table-format=3] S[table-format=1.3] S[table-format=3]
                S[table-format=1.3,
                table-space-text-post =\sym{***}]
                S[table-format=1.3] S[table-format=3]}
\toprule
            &\multicolumn{2}{c}{High ratios}&\multicolumn{2}{c}{Low ratios}&\multicolumn{3}{c}{\textit{t} test}            \\\cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-8}
            & {Mean}    & {Obs.}    & {Mean}    & {Obs.}    & {Diff.}   & {SE}  & {Obs.}    \\
\midrule
divDm       & 0.397     & 315       & 0.418     & 304       &  0.021    & 0.040 & 619       \\
divRto      & 0.144     & 315       & 0.156     & 304       &  0.013    & 0.025 & 619       \\
divYld      & 0.012     & 314       & 0.012     & 300       & -0.000    & 0.002 & 614       \\
intCov      & 3.663     & 315       & 7.267     & 304   & 3.604\sym{*}  & 1.458 & 619       \\
intCovAdj   & 1.433     & 313       & 1.687     & 304   & 0.254\sym{*}  & 0.111 & 617       \\
lvrg1       & 0.368     & 315       & 0.428     & 306   & 0.060\sym{***}& 0.015 & 621       \\
lvrg1Adj1   & 0.468     & 315       & 0.533     & 304   & 0.065\sym{***}& 0.013 & 619       \\
lvrg2       & 0.421     & 315       & 0.425     & 306   & 0.005         & 0.015 & 621       \\
lvrg2Adj1   & 0.511     & 315       & 0.517     & 304   & 0.006         & 0.012 & 619       \\
lvrg3       & 0.744     & 315       & 0.768     & 306   & 0.025         & 0.015 & 621       \\
lvrg3Adj1   & 0.781     & 315       & 0.805     & 304   & 0.024         & 0.013 & 619       \\
prfMrg      & 0.011     & 315       & 0.021     & 306   & 0.010         & 0.007 & 621       \\
prfMrgAdj   & 0.041     & 313       & 0.060     & 304   & 0.019\sym{**} & 0.006 & 617       \\
roa         & 0.016     & 315       & 0.030     & 306   & 0.014\sym{**} & 0.005 & 621       \\
roaAdj      & 0.026     & 313       & 0.039     & 303   & 0.013\sym{**} & 0.004 & 616       \\
\bottomrule
\multicolumn{8}{l}{\footnotesize * p<0.05, ** p<0.01, *** p<0.001}\\
\end{tabular*}
\end{table}

\end{document}

在此处输入图片描述

相关内容