我对 Latex 还很陌生,我有一个(至少对你来说)可能相当简单的问题,但经过一番研究,我没有找到任何对我有帮助的东西。我想做一个带有某些子表的表格,但是我的子表标题分成了几行。我更喜欢表格上方只有一行,其他位置都可以。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lscape}
\usepackage{subcaption}
\begin{document}
\begin{landscape}
\begin{table}[h]
\caption{Effects}
\begin{subtable}
\small
\caption{A subtable}
\label{tab:1a}
\begin{tabular}{l*{16}{c}}
\hline\hline
&\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)}&\multicolumn{1}{c}{(9)}&\multicolumn{1}{c}{(10)}&\multicolumn{1}{c}{(11)}&\multicolumn{1}{c}{(12)}&\multicolumn{1}{c}{(13)}&\multicolumn{1}{c}{(14)}&\multicolumn{1}{c}{(15)}\\
\hline
\# months & 0.192\sym{*} & 0.139 & 0.190\sym{*} & 0.168 & -0.019 & 0.070 & 0.065 & 0.139\sym{*} & 0.185 & 0.072 & 0.018 & 0.047 & -0.088 & 0.000 & -17.812 \\
& (1.65) & (1.28) & (1.71) & (1.13) & (-0.17) & (0.94) & (0.48) & (1.78) & (1.26) & (0.70) & (0.21) & (0.26) & (-0.86) & (.) & (-1.03) \\
[1em]
\# quartals & 0.557 & 0.406 & 0.525 & 0.485 & -0.068 & 0.227 & 0.175 & 0.437\sym{*} & 0.539 & 0.206 & 0.063 & 0.107 & -0.244 & 0.000 & -55.164 \\
& (1.63) & (1.25) & (1.58) & (1.09) & (-0.20) & (1.02) & (0.43) & (1.87) & (1.23) & (0.69) & (0.24) & (0.19) & (-0.80) & (.) & (-1.03) \\
[1em]
\# years & 2.508\sym{*} & 1.999 & 2.282\sym{*} & 2.556 & -0.405 & 0.951 & 1.366 & 1.750\sym{*} & 1.923 & 1.004 & 0.573 & 0.756 & -1.194 & 0.000 & -234.503 \\
& (1.85) & (1.54) & (1.68) & (1.45) & (-0.31) & (1.12) & (0.86) & (1.87) & (1.09) & (0.87) & (0.54) & (0.35) & (-0.95) & (.) & (-1.04) \\
\hline\hline
\end{tabular}
\end{subtable}
\hfill
\begin{subtable}
\centering
\small
\caption{A subtable}\label{tab:1b}
\begin{tabular}{l*{16}{c}}
\hline\hline
&\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)}&\multicolumn{1}{c}{(9)}&\multicolumn{1}{c}{(10)}&\multicolumn{1}{c}{(11)}&\multicolumn{1}{c}{(12)}&\multicolumn{1}{c}{(13)}&\multicolumn{1}{c}{(14)}&\multicolumn{1}{c}{(15)}\\
\hline
\# months & 0.396\sym{*} & -0.017 & 0.008 & 0.197 & 0.056 & 0.032 & 0.202 & 0.131 & 0.461\sym{*} & 0.174 & 0.299 & -0.310 & 0.283 & 0.000 & 0.398\sym{*} \\
& (1.83) & (-0.52) & (0.03) & (0.97) & (0.78) & (0.71) & (1.47) & (0.79) & (1.74) & (1.29) & (1.34) & (-1.15) & (1.06) & (.) & (1.78) \\
[1em]
\# quartals & 1.178\sym{*} & -0.057 & 0.018 & 0.593 & 0.172 & 0.098 & 0.610 & 0.400 & 1.329\sym{*} & 0.490 & 0.918 & -0.985 & 0.862 & 0.000 & 1.156\sym{*} \\
& (1.82) & (-0.58) & (0.02) & (0.98) & (0.80) & (0.72) & (1.49) & (0.80) & (1.68) & (1.25) & (1.39) & (-1.22) & (1.08) & (.) & (1.78) \\
[1em]
\# years & 4.416\sym{*} & -0.317 & -0.509 & 0.981 & 0.399 & 0.318 & 1.595 & 1.341 & 4.897 & 2.038 & 4.193 & -4.298 & 3.354 & 0.000 & 4.519 \\
& (1.71) & (-0.83) & (-0.18) & (0.41) & (0.46) & (0.67) & (0.96) & (0.70) & (1.55) & (1.37) & (1.59) & (-1.36) & (1.04) & (.) & (1.64) \\
\hline\hline
\end{tabular}
\end{subtable}
\end{table}
\end{landscape}
\end{document}
答案1
在尝试编译文档时,您应该会收到一堆错误消息。收到错误消息后,请不要查看生成的 pdf 文件,而是先尝试修复错误。
您收到的第一条错误消息是
Missing number, treated as zero.
这是因为您忘记了参数\begin{subtable}{<width>}
。例如,您可以使用\begin{subtable}{\linewidth}
。
此外,\sym
目前尚未定义。我猜,你的序言中缺少以下代码行,所以我添加了它:
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
通过上述更改,您的代码现在可以编译而不会出现错误消息,但仍会抛出一些过满框警告,因为您的表格比可用空间宽。因此,我添加了\setlength{\tabcolsep}{0pt}
并使用\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l*{16}{c}}
来\begin{tabular}{l*{16}{c}}
确保您的表格 a) 宽度相等且 b) 适合可用空间。
以下是完整的 MWE:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lscape}
\usepackage{subcaption}
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{document}
\begin{landscape}
\begin{table}[h]
\setlength{\tabcolsep}{0pt}
\caption{Effects}
\begin{subtable}{\linewidth}
\small
\caption{A subtable}
\label{tab:1a}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l*{16}{c}}
\hline\hline
&\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)}&\multicolumn{1}{c}{(9)}&\multicolumn{1}{c}{(10)}&\multicolumn{1}{c}{(11)}&\multicolumn{1}{c}{(12)}&\multicolumn{1}{c}{(13)}&\multicolumn{1}{c}{(14)}&\multicolumn{1}{c}{(15)}\\
\hline
\# months & 0.192\sym{*} & 0.139 & 0.190\sym{*} & 0.168 & -0.019 & 0.070 & 0.065 & 0.139\sym{*} & 0.185 & 0.072 & 0.018 & 0.047 & -0.088 & 0.000 & -17.812 \\
& (1.65) & (1.28) & (1.71) & (1.13) & (-0.17) & (0.94) & (0.48) & (1.78) & (1.26) & (0.70) & (0.21) & (0.26) & (-0.86) & (.) & (-1.03) \\
[1em]
\# quartals & 0.557 & 0.406 & 0.525 & 0.485 & -0.068 & 0.227 & 0.175 & 0.437\sym{*} & 0.539 & 0.206 & 0.063 & 0.107 & -0.244 & 0.000 & -55.164 \\
& (1.63) & (1.25) & (1.58) & (1.09) & (-0.20) & (1.02) & (0.43) & (1.87) & (1.23) & (0.69) & (0.24) & (0.19) & (-0.80) & (.) & (-1.03) \\
[1em]
\# years & 2.508\sym{*} & 1.999 & 2.282\sym{*} & 2.556 & -0.405 & 0.951 & 1.366 & 1.750\sym{*} & 1.923 & 1.004 & 0.573 & 0.756 & -1.194 & 0.000 & -234.503 \\
& (1.85) & (1.54) & (1.68) & (1.45) & (-0.31) & (1.12) & (0.86) & (1.87) & (1.09) & (0.87) & (0.54) & (0.35) & (-0.95) & (.) & (-1.04) \\
\hline\hline
\end{tabular*}
\end{subtable}
\hfill
\begin{subtable}{\linewidth}
\centering
\small
\caption{A subtable}\label{tab:1b}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l*{16}{c}}
\hline\hline
&\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)}&\multicolumn{1}{c}{(9)}&\multicolumn{1}{c}{(10)}&\multicolumn{1}{c}{(11)}&\multicolumn{1}{c}{(12)}&\multicolumn{1}{c}{(13)}&\multicolumn{1}{c}{(14)}&\multicolumn{1}{c}{(15)}\\
\hline
\# months & 0.396\sym{*} & -0.017 & 0.008 & 0.197 & 0.056 & 0.032 & 0.202 & 0.131 & 0.461\sym{*} & 0.174 & 0.299 & -0.310 & 0.283 & 0.000 & 0.398\sym{*} \\
& (1.83) & (-0.52) & (0.03) & (0.97) & (0.78) & (0.71) & (1.47) & (0.79) & (1.74) & (1.29) & (1.34) & (-1.15) & (1.06) & (.) & (1.78) \\
[1em]
\# quartals & 1.178\sym{*} & -0.057 & 0.018 & 0.593 & 0.172 & 0.098 & 0.610 & 0.400 & 1.329\sym{*} & 0.490 & 0.918 & -0.985 & 0.862 & 0.000 & 1.156\sym{*} \\
& (1.82) & (-0.58) & (0.02) & (0.98) & (0.80) & (0.72) & (1.49) & (0.80) & (1.68) & (1.25) & (1.39) & (-1.22) & (1.08) & (.) & (1.78) \\
[1em]
\# years & 4.416\sym{*} & -0.317 & -0.509 & 0.981 & 0.399 & 0.318 & 1.595 & 1.341 & 4.897 & 2.038 & 4.193 & -4.298 & 3.354 & 0.000 & 4.519 \\
& (1.71) & (-0.83) & (-0.18) & (0.41) & (0.46) & (0.67) & (0.96) & (0.70) & (1.55) & (1.37) & (1.59) & (-1.36) & (1.04) & (.) & (1.64) \\
\hline\hline
\end{tabular*}
\end{subtable}
\end{table}
\end{landscape}
\end{document}