我正在测试 Stata → LaTeX 集成,阅读了一些指南,我对结果感到满意。不幸的是,似乎只能dcolumn
在 Stata 中使用该包。我知道这个siunitx
包是这里很多人喜欢的包,所以我手动更改了那部分代码。但是,由于某种原因,***
3673.1 上的星星()很远,并且(
相应标准误差估计的未正确对齐。我不确定哪里出了问题?不要担心双重估计,我错误地没有清除该eststo
函数。
这是一张图片:
对我来说,该代码看起来不是特别干净(它是使用esttab
Stata 中的命令生成的),但它完成了它的工作。
平均能量损失
\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{input-symbols = ()}
\begin{document}
\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{This is a regression table\label{tab1}}
\begin{tabular}{l*{4}{S}}
\toprule
&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}\\
&\multicolumn{1}{c}{Price}&\multicolumn{1}{c}{Price}&\multicolumn{1}{c}{Price}&\multicolumn{1}{c}{Price}\\
\midrule
Weight (lbs.) & 1.747\sym{**} & 3.465\sym{***}& 1.747\sym{**} & 3.465\sym{***}\\
& (0.641) & (0.631) & (0.641) & (0.631) \\
\addlinespace
Mileage (mpg) & -49.51 & 21.85 & -49.51 & 21.85 \\
& (86.16) & (74.22) & (86.16) & (74.22) \\
\addlinespace
Car type & & 3673.1\sym{***}& & 3673.1\sym{***}\\
& & (684.0) & & (684.0) \\
\addlinespace
Constant & 1946.1 & -5853.7 & 1946.1 & {-5853.7} \\
& (3597.0) & (3377.0) & (3597.0) & (3377.0) \\
\midrule
Observations & {74} & {74} & {74} & {74} \\
Adjusted \(R^{2}\) & 0.273 & 0.478 & 0.273 & 0.478 \\
\bottomrule
\multicolumn{5}{l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{5}{l}{\footnotesize Source: UCT Institutional Planning Department}\\
\multicolumn{5}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \ (p<0.001\)}\\
\end{tabular}
\end{table}
\end{document}
答案1
你需要说siunitx
两件事:
保留注释标记的空间。这是通过命令
\sisetup{table-space-text-post = \sym{***}}
不要对齐附加文本,因此它可能被放置在靠近数字的位置:
\begin{tabular}{l*{4}{S[table-align-text-post=false]}}
结果如下
\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\pagestyle{empty}
\sisetup{input-symbols = ()}
\begin{document}
\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{This is a regression table\label{tab1}}
\sisetup{table-space-text-post = \sym{***}}
\begin{tabular}{l*{4}{S[table-align-text-post=false]}}
\toprule
&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}\\
&\multicolumn{1}{c}{Price}&\multicolumn{1}{c}{Price}&\multicolumn{1}{c}{Price}&\multicolumn{1}{c}{Price}\\
\midrule
Weight (lbs.) & 1.747\sym{**} & 3.465\sym{***}& 1.747\sym{**} & 3.465\sym{***}\\
& (0.641) & (0.631) & (0.641) & (0.631) \\
\addlinespace
Mileage (mpg) & -49.51 & 21.85 & -49.51 & 21.85 \\
& (86.16) & (74.22) & (86.16) & (74.22) \\
\addlinespace
Car type & & 3673.1\sym{***}& & 3673.1\sym{***}\\
& & (684.0) & & (684.0) \\
\addlinespace
Constant & 1946.1 & -5853.7 & 1946.1 & {-5853.7} \\
& (3597.0) & (3377.0) & (3597.0) & (3377.0) \\
\midrule
Observations & {74} & {74} & {74} & {74} \\
Adjusted \(R^{2}\) & 0.273 & 0.478 & 0.273 & 0.478 \\
\bottomrule
\multicolumn{5}{l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{5}{l}{\footnotesize Source: UCT Institutional Planning Department}\\
\multicolumn{5}{l}{\footnotesize \sym{*} $p<0.05$, \sym{**} $p<0.01$, \sym{***} \ ($p<0.001$}\\
\end{tabular}
\end{table}
\end{document}
答案2
从siunitx
版本 3 开始,可以直接输入数值前后的文本占位符table-format
。这应该是列中使用的最宽文本,以保留适当的间距。使用\sym
已过时。
\begin{tabular}{ S[table-format=1.3{***} ]
可以通过选项table-align-text-before
和来控制对齐table-align-text-after
:
\begin{tabular}{ S[table-format=1.3{***}, table-align-text-after=false ]
得出:
\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\pagestyle{empty}
\sisetup{input-symbols = ()}
\begin{document}
\begin{table}\centering
\caption{This is a regression table\label{tab1}}
\begin{tabular}{l*{4}{S[table-format=-4.3{***}, table-align-text-after=false]}}
\toprule
&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}\\
&\multicolumn{1}{c}{Price}&\multicolumn{1}{c}{Price}&\multicolumn{1}{c}{Price}&\multicolumn{1}{c}{Price}\\
\midrule
Weight (lbs.) & 1.747{**}& 3.465{***}& 1.747{**}& 3.465{***}\\
& (0.641) & (0.631) & (0.641) & (0.631) \\
\addlinespace
Mileage (mpg) & -49.51 & 21.85 & -49.51 & 21.85 \\
& (86.16) & (74.22) & (86.16) & (74.22) \\
\addlinespace
Car type & & 3673.1{***}& & 3673.1{***}\\
& & (684.0) & & (684.0) \\
\addlinespace
Constant & 1946.1 & -5853.7 & 1946.1 & -5853.7 \\
& (3597.0) & (3377.0) & (3597.0) & (3377.0) \\
\midrule
Observations & {74} & {74} & {74} & {74} \\
Adjusted \(R^{2}\)& 0.273 & 0.478 & 0.273 & 0.478 \\
\bottomrule
\multicolumn{5}{l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{5}{l}{\footnotesize Source: UCT Institutional Planning Department}\\
\multicolumn{5}{l}{\footnotesize {*} $p<0.05$, {**} $p<0.01$, {***} \ $p<0.001$}\\
\end{tabular}
\end{table}
\end{document}