早上好,我尝试自己搜索来解决问题。我确实找到了一些帖子,但不幸的是,我无法解决我的问题。我的表格宽度太大,不适合页面。但是,我正在研究的一篇经济学论文中有完全相同的图表,完全适合页面。
这是我的代码:
\documentclass [a4paper,12 pt]{article}
\usepackage{tabu}
\usepackage{longtable}
\begin{document}
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{longtabu}to \linewidth {l*{8}{X}}
\caption{Relation between Average Annual Wages in USD and selected Indicators}\\
\hline\hline\endfirsthead\hline\endhead\hline\endfoot\endlastfoot
&&&\multicolumn{1}{c}{TFP\_OLSFE}&&&\multicolumn{1}{c}{TFP\_OP}\\
&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}&\multicolumn{1}{c}{(7)}&\multicolumn{1}{c}{(8)}\\
\hline
comp\_herfsubsidy& 0.0382\sym{***}& & & 0.0309\sym{***}& 0.0430\sym{***}& & & 0.0343\sym{***}\\
& (0.00911) & & & (0.00726) & (0.0103) & & & (0.00827) \\
[1em]
cor\_subsidy\_lerner& 0.00433 & & & 0.000921 & 0.00307 & & & 0.000547 \\
& (0.00353) & & & (0.00365) & (0.00354) & & & (0.00373) \\
[1em]
cor\_tariff\_lerner& -0.0157 & -0.00164 & -0.00769 & -0.00951 & -0.00643 & 0.00341 & -0.00351 & 0.00185 \\
& (0.0129) & (0.00900) & (0.00972) & (0.0130) & (0.0136) & (0.00983) & (0.0107) & (0.0137) \\
[1em]
lerner & 13.38\sym{*} & 10.75\sym{**} & 11.09\sym{**} & 12.69\sym{*} & 16.66\sym{*} & 10.79\sym{*} & 11.36\sym{*} & 15.58\sym{*} \\
& (5.570) & (3.677) & (3.692) & (5.403) & (7.416) & (4.242) & (4.297) & (7.268) \\
[1em]
lernersquare& -7.645\sym{*} & -6.139\sym{**} & -6.338\sym{**} & -7.290\sym{*} & -9.061\sym{*} & -5.945\sym{*} & -6.264\sym{*} & -8.494\sym{*} \\
& (3.056) & (2.029) & (2.040) & (2.967) & (4.064) & (2.379) & (2.412) & (3.987) \\
\hline
\(N\) & 1088635 & 1203999 & 1278474 & 1007014 & 1088635 & 1203999 & 1278474 & 1007014 \\
adj. \(R^{2}\)& 0.214 & 0.218 & 0.214 & 0.220 & 0.183 & 0.189 & 0.185 & 0.189 \\
\hline\hline
\multicolumn{9}{l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{9}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{longtabu}
}
\end{document}
我觉得 longtable 看起来有点奇怪 - 尤其是开头的代码 - 但这是因为我使用 STATA 来计算值并生成 longtable。但是,自从我尝试了这里的解决方案后,我已经用 \begin{longtabu} 更改了行:设置 longtable 以适合页面宽度 现在各列重叠了,我不知道该怎么办。
感谢您的帮助!
答案1
我建议使用landscape
环境和xltabular
和threeparttablex
包。前者将的功能带到了longtable
,tabularx
后者是的扩展threeparttable
,语法略有不同,这使得表格注释在 longtable 中可用。我还使用了 `siunitx 来对齐小数点上的数字。
\documentclass [a4paper,12 pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xltabular}
\usepackage{threeparttablex}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{lscape}
\begin{document}
\begin{landscape}
\small
\setlength{\tabcolsep}{2pt}
\sisetup{table-format=-1.6,table-number-alignment=center, table-space-text-pre=(, table-space-text-post=\tnote{***}, table-align-text-pre=false, table-align-text-post=false}
\begin{ThreePartTable}
\begin{TableNotes}[para, flushleft]
\smallskip
\footnotesize \item[]Standard errors in parentheses:
\item[*]\(p<0.05\),
\item[**]\(p<0.01\),
\item[***]\(p<0.001\).
\end{TableNotes}
\begin{xltabular}{\linewidth} {X*{8}{S}}
\caption{Relation between Average Annual Wages in USD and selected Indicators}\\
\toprule\endfirsthead\midrule\endhead\midrule\endfoot\endlastfoot
cor\_subsidy\_lerner & 0.00433 & & & 0.000921 & 0.00307 & & & 0.000547 \\
& {(}0.00353{)} & & & {(}0.00365{)} & {(}0.00354{)} & & & {(}0.00373{)} \\
[1em]
cor\_tariff\_lerner& -0.0157 & -0.00164 & -0.00769 & -0.00951 & -0.00643 & 0.00341 & -0.00351 & 0.00185 \\
& {(}0.0129{)} & {(}0.00900{)} & {(}0.00972{)} & {(}0.0130{)} & {(}0.0136{)} & {(}0.00983{)} & {(}0.0107{)} & {(}0.0137{)} \\
[1em]
lerner & 13.38\tnote{*} & 10.75\tnote{**} & 11.09\tnote{**} & 12.69\tnote{*} & 16.66\tnote{*} & 10.79\tnote{*} & 11.36\tnote{*} & 15.58\tnote{*} \\
& {(}5.570{)} & {(}3.677{)} & {(}3.692{)} & {(}5.403{)} & {(}7.416{)} & {(}4.242{)} & {(}4.297{)} & {(}7.268{)} \\
[1em]
lernersquare& -7.645\tnote{*} & -6.139\tnote{**} & -6.338\tnote{**} & -7.290\tnote{*} & -9.061\tnote{*} & -5.945\tnote{*} & -6.264\tnote{*} & -8.494\tnote{*} \\
& {(}3.056{)} & {(}2.029{)} & {(}2.040{)} & {(}2.967{)} & {(}4.064{)} & {(}2.379{)} & {(}2.412{)} & {(}3.987{)} \\
\midrule
\(N\) & \num{1088635} & \num{1203999} & \num{1278474} & \num{1007014} & \num{1088635} & \num{1203999} & \num{1278474} & \num{1007014} \\
adj. \(R^{2}\)& 0.214 & 0.218 & 0.214 & 0.220 & 0.183 & 0.189 & 0.185 & 0.189 \\
\bottomrule
\insertTableNotes
\end{xltabular}
\end{ThreePartTable}
\end{landscape}
\end{document}
编辑:关于纵向布局的建议:
\documentclass [a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[showframe]{geometry}
\usepackage{xltabular}
\usepackage{threeparttablex}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage[svgnames, table]{xcolor}
\usepackage{lscape}
\begin{document}
\vspace*{2\baselineskip}
\begin{ThreePartTable}
\footnotesize
\setlength{\tabcolsep}{2pt}
\sisetup{table-format=-1.6,table-number-alignment=center, table-space-text-pre=(, table-space-text-post=\tnote{***}, table-align-text-pre=false, table-align-text-post=false}
\captionsetup{font={footnotesize, sc}, labelsep=endash, skip=5pt}
\begin{TableNotes}[para, flushleft]
\smallskip
\footnotesize \item[]Standard errors in parentheses:
\item[*]\(p<0.05\),
\item[**]\(p<0.01\),
\item[***]\(p<0.001\).
\end{TableNotes}
\begin{xltabular}{\linewidth} {X*{8}{S}}
\caption{Relation between Average Annual Wages in USD and selected Indicators}\\
\toprule \arrayrulecolor{Gainsboro!75}\specialrule{\aboverulesep}{-\belowrulesep}{-\aboverulesep} \arrayrulecolor{black} \midrule\endfirsthead\midrule\endhead\midrule\endfoot\endlastfoot
\multicolumn{2}{l}{cor\_subsidy\_lerner}& & & & & & \\
& 0.00433 & & & 0.000921 & 0.00307 & & & 0.000547 \\
& {(}0.00353{)} & & & {(}0.00365{)} & {(}0.00354{)} & & & {(}0.00373{)} \\
[1.5ex]
\multicolumn{2}{l}{cor\_tariff\_lerner} & & & & & & \\
& -0.0157 & -0.00164 & -0.00769 & -0.00951 & -0.00643 & 0.00341 & -0.00351 & 0.00185 \\
& {(}0.0129{)} & {(}0.00900{)} & {(}0.00972{)} & {(}0.0130{)} & {(}0.0136{)} & {(}0.00983{)} & {(}0.0107{)} & {(}0.0137{)} \\[1.5ex]
\multicolumn{1}{l}{lerner} & 13.38\tnote{*} & 10.75\tnote{**} & 11.09\tnote{**} & 12.69\tnote{*} & 16.66\tnote{*} & 10.79\tnote{*} & 11.36\tnote{*} & 15.58\tnote{*} \\
& {(}5.570{)} & {(}3.677{)} & {(}3.692{)} & {(}5.403{)} & {(}7.416{)} & {(}4.242{)} & {(}4.297{)} & {(}7.268{)} \\[1.5ex]
%
\multicolumn{2}{l}{ lernersquare}\\& -7.645\tnote{*} & -6.139\tnote{**} & -6.338\tnote{**} & -7.290\tnote{*} & -9.061\tnote{*} & -5.945\tnote{*} & -6.264\tnote{*} & -8.494\tnote{*} \\
& {(}3.056{)} & {(}2.029{)} & {(}2.040{)} & {(}2.967{)} & {(}4.064{)} & {(}2.379{)} & {(}2.412{)} & {(}3.987{)} \\
\midrule
\(N\) & {\num{1088635}} & {\num{1203999}} & {\num{1278474}} & {\num{1007014}} & {\num{1088635}} & {\num{1203999}} & {\num{1278474}} & {\num{1007014}} \\
adj. \(R^{2}\)& 0.214 & 0.218 & 0.214 & 0.220 & 0.183 & 0.189 & 0.185 & 0.189 \\
\bottomrule
\insertTableNotes
\end{xltabular}
\end{ThreePartTable}
\end{document}
答案2
- 如果您的表格内容仅仅是您在 MWE 中显示的内容,那么您就不需要环境
longtable
了tabular
。 - 相反,
X
我建议使用包S
中定义的列类型siunitx
- 您的表格太宽,无法容纳文本宽度。我会考虑使用“横向布局”表格。可以使用以下方法实现此目的:
- 使用
pdflscape
包(如下面 MWE 中使用的),或者 - 使用包
sideways
中定义的表rotating
- 使用
梅威瑟:
\documentclass [a4paper,12 pt]{article}
\usepackage{pdflscape}
\usepackage{booktabs}
\usepackage[referable]{threeparttablex}
\usepackage{siunitx}
\usepackage{lipsum} % for dummy text
\begin{document}
\begin{landscape}
\small
\setlength\tabcolsep{0pt}
\centering
\sisetup{input-symbols = {( )},
table-space-text-pre={(},
table-space-text-post={$^{***}$},
table-align-text-post=false,
table-format=-1.5
}
\begin{threeparttable}[ht]
\caption{Relation between Average Annual Wages in USD and selected Indicators}
\begin{tabular*}{\linewidth} {@{\extracolsep{\fill}} l*{8}{S} @{}}
\toprule
& \multicolumn{4}{c}{TFP\_OLSFE} & \multicolumn{4}{c}{TFP\_OP} \\
\cmidrule(lr){2-5}\cmidrule(lr){6-9}
& {(1)} & {(2)} & {(3)} & {(4)} & {(5)} & {(6)} & {(7)} & {(8)} \\
\midrule
comp\_herfsubsidy
& 0.0382\tnote{***} & & & 0.0309\tnote{***} & 0.0430\tnote{***} & & & 0.0343\tnote{***} \\
& (0.00911) & & & (0.00726) & (0.0103) & & &(0.00827) \\
\addlinespace
cor\_subsidy\_lerner
& 0.00433 & & & 0.000921 & 0.00307 & & & 0.000547 \\
& (0.00353) & & & (0.00365) & (0.00354) & & & (0.00373) \\
\addlinespace
cor\_tariff\_lerner
& -0.0157 &-0.00164 & -0.00769 & -0.00951 & -0.00643 & 0.00341 & -0.00351 & 0.00185 \\
& (0.0129)& (0.00900) & (0.00972) & (0.0130) & (0.0136) & (0.00983) & (0.0107) & (0.0137) \\
\addlinespace
lerner
& 13.38\tnote{*} & 10.75\tnote{**} & 11.09\tnote{**} & 12.69\tnote{*}
& 16.66\tnote{*} & 10.79\tnote{*} & 11.36\tnote{*} & 15.58\tnote{*} \\
& (5.570) & (3.677) & (3.692) & (5.403)
& (7.416) & (4.242) & (4.297) & (7.268) \\
\addlinespace
lernersquare
& -7.645\tnote{*} & -6.139\tnote{**} & -6.338\tnote{**} & -7.290\tnote{*}
& -9.061\tnote{*} & -5.945\tnote{*} & -6.264\tnote{*} & -8.494\tnote{*} \\
& (3.056) & (2.029) & (2.040) & (2.967)
& (4.064) & (2.379) & (2.412) & (3.987) \\
\midrule
\(N\)
& \num{1088635} & \num{1203999} & \num{1278474} & \num{1007014}
& \num{1088635} & \num{1203999} & \num{1278474} & \num{1007014} \\
adj. \(R^{2}\)
& 0.214 & 0.218 & 0.214 & 0.220
& 0.183 & 0.189 & 0.185 & 0.189 \\
\bottomrule
\end{tabular*}
\begin{tablenotes}[flushleft]\footnotesize
\note \lipsum[1]
\item[*] Significant at \SI{10}{\%} level
\item[**] Significant at \SI{5}{\%} level
\item[***] Significant at \SI{1}{\%} level
\end{tablenotes}
\end{threeparttable}
\end{landscape}
\end{document}