我正在尝试构建一个包含两个面板且列数不同的表格。例如:
Table 1: An interesting table
Panel A: Some stuff
First name Last name Product
Bubba Gump Shrimp
Steve Jobs Happiness
Panel B: Other stuff
School State
Harvard MA
Yale CT
Brown RI
我希望面板 A 的 3 列和面板 B 的 2 列填满表格的水平空间。
我曾想象在 \table 中使用两个不同的 \tabular 命令会起作用,但事实并非如此。我还找到了该subfigure
包,但我认为这只允许您水平堆叠表格,而不能垂直堆叠。
有什么想法吗?谢谢!
答案1
在表格环境中,您可以使用不同类型的表格环境,以及不同数量的列。以下是带有子标题的示例:
\documentclass{article}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tabularx}
\begin{document}
\begin{table}
\centering
\caption{An interesting table}
\subcaption*{Panel A: Some stuff}
\begin{tabular}{lcr}
First name & Last name & Product \\
Bubba & Gump & Shrimp \\
Steve & Jobs & Happiness
\end{tabular}
\bigskip
\subcaption*{Panel B: Other stuff}
\begin{tabular}{ll}
School & State \\
Harvard & MA \\
Yale & CT \\
Brown & RI
\end{tabular}
\end{table}
\end{document}
在这里我使用了subcaption
包。一个好的替代方案是subfig
包。然而,subfigure
包裹是过时的。
答案2
通过自由使用该\multicolumn{.}{.}{...}
命令,您可以将表格扩展到整个\linewidth
:
\documentclass{article}
\usepackage{array,booktabs}
\begin{document}
\begin{table}[ht]
\centering
\caption{An interesting table}
\label{tbl:interesting}
\begin{tabular}{*{6}{p{.16\linewidth}}}
\multicolumn{6}{c}{Panel A: Some stuff} \\
\toprule
\multicolumn{2}{p{.33\linewidth}}{First name} & \multicolumn{2}{p{.33\linewidth}}{Last name} &
\multicolumn{2}{p{.33\linewidth}}{Product} \\
\midrule
\multicolumn{2}{l}{Bubba} & \multicolumn{2}{l}{Gump} & \multicolumn{2}{l}{Shrimp} \\
\multicolumn{2}{l}{Steve} & \multicolumn{2}{l}{Jobs} & \multicolumn{2}{l}{Happiness} \\
\bottomrule
\\
\multicolumn{6}{c}{Panel B: Other stuff} \\
\toprule
\multicolumn{3}{p{.49\linewidth}}{School} & \multicolumn{3}{p{.49\linewidth}}{State} \\
\midrule
\multicolumn{3}{l}{Harvard} & \multicolumn{3}{l}{MA} \\
\multicolumn{3}{l}{Yale} & \multicolumn{3}{l}{CT} \\
\multicolumn{3}{l}{Brown} & \multicolumn{3}{l}{RI} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
由于两个面板包含在同一个 中tabular
,因此它们跨度相同。以上使用booktabs
包裹用于环境的呈现tabular
。但是,这并非必需。如果您想要删除它,您还应该删除/替换\toprule
、\midrule
和\bottomrule
规则,并使用\hline
或其他首选项。
或者,您也可以使用tabularx
包裹将列分布到特定的宽度:
\documentclass{article}
\usepackage{booktabs,tabularx}
\begin{document}
\begin{table}[ht]
\centering
\caption{An interesting table}
\label{tbl:interesting}
\medskip
\begin{tabularx}{\linewidth}{ X X X }
\multicolumn{3}{c}{Panel A: Some stuff} \\
\toprule
First name & Last name & Product \\
\midrule
Bubba & Gump & Shrimp \\
Steve & Jobs & Happiness \\
\bottomrule
\end{tabularx}
\bigskip
\begin{tabularx}{\linewidth}{ X X }
\multicolumn{2}{c}{Panel B: Other stuff} \\
\toprule
School & State \\
\midrule
Harvard & MA \\
Yale & CT \\
Brown & RI \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案3
您可以使用multicol
列包可以使数据跨越多列。
\documentclass{article}
\usepackage{multicol}
\begin{document}
\begin{tabular}{lll}
\multicolumn{3}{c}{Panel A: Some stuff}\\
First name &Last name &Product\\
Bubba &Gump &Shrimp\\
Steve &Jobs &Happiness\\
\\
\multicolumn{3}{c}{Panel B: Other stuff}\\
School &State\\
Harvard &MA\\
Yale &CT\\
Brown &RI\\
\end{tabular}
\end{document}
答案4
也许像这样?
\begin{tabular}{lll}
\hline
\multicolumn{ 3}{c}{Panel A: Some stuff} \\
\hline
First name & Last name & Product \\
\hline
Bubba & Gump & Shrimp \\
\hline
Steve & Jobs & Happines \\
\hline
\multicolumn{ 3}{c}{Panel B: Other stuff} \\
\hline
School & \multicolumn{ 2}{l}{State} \\
\hline
Harvard & \multicolumn{ 2}{l}{CT} \\
\hline
Yale & \multicolumn{ 2}{l}{CI} \\
\hline
Brown & \multicolumn{ 2}{l}{RI} \\
\hline
\end{tabular}