![latex 中的表格问题](https://linux22.com/image/353762/latex%20%E4%B8%AD%E7%9A%84%E8%A1%A8%E6%A0%BC%E9%97%AE%E9%A2%98.png)
我正在用乳胶写一些表格。我的 MWE 是:
\documentclass{article}
\usepackage{rotating}
\usepackage{xcolor}
\usepackage{longtable}
\usepackage[labelfont=bf]{caption}
\usepackage[utf8]{inputenc}
\usepackage{caption, booktabs, makecell, siunitx}
\usepackage{eqparbox}
\pagenumbering{gobble}
\usepackage{booktabs}
\usepackage[referable,para]{threeparttablex}
\usepackage[textheight=27cm, textwidth=15cm]{geometry}
\usepackage{multirow}
\usepackage{pdflscape}
\sisetup{group-separator={,}, table-format=1.3, table-space-text-post=***,
table-number-alignment =center}
\newcommand*{\MyIndent}
{\hspace*{1.5cm}}
\begin{document}
\begin{sidewaystable}[htbp]\centering\normalsize{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Baseline model \label{table3}}
\begin{tabular}{l*{5}{c}}
\hline\hline
&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}\\
\hline
lwlnyw &.984\sym{***}& .674\sym{***}& & .519\sym{***}& .957\sym{***}\\
& (.007) & (.043) & & (.128) & (.013) \\
pc & -.029\sym{**} & -.045\sym{***}& -.033\sym{***}& -.103\sym{***}& -.107\sym{***}\\
& (.015) & (.013) & (.013) & (.039) & (.036) \\
pc2 & .003\sym{**} & .004\sym{***}& .003\sym{***}& .010\sym{***}& .011\sym{***}\\
& (.001) & (.001) & (.001) & (.004) & (.003) \\
lnsnda2 & & & & & \\
& & & & & \\
\hline
Observations & 681 & 681 & 681 & 553 & 681 \\
N. of Observations & & 119 & 119 & 119 & 119 \\
Overall-R$^2$ & & .988 & & & \\
R$^2$ & .989 & .723 & & & \\
F-test & 5531.466 & 85.460 & & & \\
log(likelihood) & 401.638 & 621.943 & & & \\
\hline\hline
\multicolumn{6}{l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{6}{l}{\footnotesize \sym{*} \(p<0.10\), \sym{**} \(p<0.05\), \sym{***} \(p<0.01\)}\\
\end{tabular}}
\end{sidewaystable}
\end{document}
如果你看一下 pdf,你会注意到:
1) 表示列的数字附在上面的双线上。我尝试使用\\
或\vspace
来\hline\hline
获得更多空间。然而,实际情况是,在数字下方而不是上方创建了更多空间。我该如何解决这个问题?
2) 我希望列之间有更多空间。在 Excel 中,我习惯添加长度非常小的额外列。如何在 Latex 中执行相同操作?
谢谢,达里奥
答案1
我建议你们做以下改变:
为了获得间距更好的水平线,请不要使用
\hline
和\cline
。而是使用包的线条绘制宏booktabs
(您已经加载):\toprule
,\midrule
,\bottomrule
,\cmidrule
和\addlinespace
。要增加列间空白量,请增加长度参数的值
\tabcolsep
。其默认值为6pt
;在下面的代码中,我使用9pt
。您可以随意设置此参数以满足您的需求。由于您正在加载
siunitx
包,因此您不妨将其S
列类型用于五个数据列。
\documentclass{article}
% I've reduced the preamble to the bare minimum needed to get the code to compile
\usepackage[labelfont=bf,skip=0.333\baselineskip]{caption}
\usepackage[utf8]{inputenc}
\usepackage{booktabs, siunitx}
\usepackage[textheight=27cm, textwidth=15cm]{geometry}
\sisetup{group-separator={},
table-format=-1.3,
input-symbols={()},
table-space-text-post=***}
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\pagenumbering{gobble}
\begin{document}
\begin{table}[htbp] % no need to use a 'sidewaystable' here, right?
\setlength{\tabcolsep}{9pt} % default: 6pt
\normalsize
\centering
\caption{Baseline model \label{table3}}
\begin{tabular}{@{} l *{5}{S} @{}}
\toprule
& {(1)} & {(2)} & {(3)} & {(4)} & {(5)}\\
\midrule
lwlnyw & .984\sym{***}& .674\sym{***}& & .519\sym{***} & .957\sym{***}\\
& (.007) & (.043) & & (.128) & (.013) \\
pc & -.029\sym{**} & -.045\sym{***}& -.033\sym{***}& -.103\sym{***} & -.107\sym{***}\\
& (.015) & (.013) & (.013) & (.039) & (.036) \\
pc2 & .003\sym{**} & .004\sym{***}& .003\sym{***}& .010\sym{***}& .011\sym{***}\\
& (.001) & (.001) & (.001) & (.004) & (.003) \\
lnsnda2 \\
\\
\midrule
Observations & {681} & {681} & {681} & {553} & {681} \\
N.\ of Obs. & & {119} & {119} & {119} & {119} \\
Overall $R^2$ & & .988 \\
$R^2$ & .989 & .723 \\
F-test & {5531.5} & {85.5} \\
Log-likelihood & {401.6} & {621.9} \\
\bottomrule
\addlinespace % a bit of (vertical) whitespace
\multicolumn{6}{@{}l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{6}{@{}l}{\footnotesize $\sym{*}\ p<0.10$; $\sym{**}\ p<0.05$; $\sym{***}\ p<0.01$}\\
\end{tabular}
\end{table}
\end{document}