我想在 threeparttable 环境中并排显示两个表格,由于有浮动选项,该环境也位于表格环境中。但是,我得到的表格一个在另一个之上。我明确地更喜欢使用 threeparttable 环境,因为这样更容易使用表格注释。这是我的代码:
\begin{table}[hbtp]
\caption{Participation Rates by Demographic Group}
\label{participation_rates}
\centering
\footnotesize
\begin{threeparttable}
\begin{tabular}{cccc} \hline \hline
\multicolumn{4}{c}{First Order Rates} \\
& & & \\
& & \multicolumn{2}{c}{ mother's education} \\
& & hs less & coll more \\
& & & \\
\multirow{2}[0]{*}{single} & black & 0.7983 & 0.6165 \\
& white & 0.6105 & 0.4144 \\
& & & \\
& & & \\
\multirow{2}[0]{*}{married} & black & 0.3286 & 0.1946 \\
& white & 0.1938 & 0.1118 \\ \hline \hline
\end{tabular}
\hfill
\begin{tabular}{cccc} \hline \hline
\multicolumn{4}{c}{Second Order Rates} \\
& & & \\
& & \multicolumn{2}{c}{ mother's education} \\
& & hs less & coll more \\
& & & \\
\multirow{2}[0]{*}{single} & black & 0.6502 & 0.4230 \\
& white & 0.4547 & 0.2695 \\
& & & \\
& & & \\
\multirow{2}[0]{*}{married} & black & 0.2789 & 0.1438 \\
& white & 0.1562 & 0.06453 \\ \hline \hline
\end{tabular}
\begin{tablenotes}
\footnotesize
\item Here are some table notes...
\end{tablenotes}
\end{threeparttable}
\end{table}
答案1
将两个四列表格都放在“外部”两列tabular
环境中:
\documentclass{article}
\usepackage{multirow, threeparttable}
\begin{document}
\begin{table}[hbtp]
\begin{threeparttable}
\caption{Participation Rates by Demographic Group}
\label{participation_rates}
\centering
\footnotesize
\begin{tabular}{cc} % <-- new
\begin{tabular}{cccc} \hline \hline
\multicolumn{4}{c}{First Order Rates} \\
& & & \\
& & \multicolumn{2}{c}{ mother's education} \\
& & hs less & coll more \\
& & & \\
\multirow{2}[0]{*}{single} & black & 0.7983 & 0.6165 \\
& white & 0.6105 & 0.4144 \\
& & & \\
& & & \\
\multirow{2}[0]{*}{married} & black & 0.3286 & 0.1946 \\
& white & 0.1938 & 0.1118 \\ \hline \hline
\end{tabular}
&
\begin{tabular}{cccc} \hline \hline
\multicolumn{4}{c}{Second Order Rates} \\
& & & \\
& & \multicolumn{2}{c}{ mother's education} \\
& & hs less & coll more \\
& & & \\
\multirow{2}[0]{*}{single} & black & 0.6502 & 0.4230 \\
& white & 0.4547 & 0.2695 \\
& & & \\
& & & \\
\multirow{2}[0]{*}{married} & black & 0.2789 & 0.1438 \\
& white & 0.1562 & 0.06453 \\ \hline \hline
\end{tabular}
\end{tabular} % <-- new
\begin{tablenotes}
\footnotesize
\item Here are some table notes...
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
答案2
正如您(重新)发现的那样,threeparttable
环境使用第一个类似环境的宽度tabular
来确定其他两个主要元素(标题和tablenotes
环境)的宽度。由于threeparttable
预计只“看到”一个环境,因此它会在代码中的tabular
第二个环境之前强制换行。tabular
假设您想保留threeparttable
机器,因此必须让它相信只有一台机器tabular
需要处理,您可以按如下方式进行:
使用@Zarko 的方法并将两个四列环境嵌入“外部”两列
tabular
环境中。设置单列“外部”
tabular
环境,并在其中嵌套minipage
宽度为 的\textwidth
。这种方法将在下文中详细解释。
第二种方法有一个重要的优点:它允许自然地使用subtable
环境(由包提供subcaption
)。以下代码显示了如何做到这一点。请注意,我为两个表提供了更明确的视觉结构,并且不再需要将\footnotesize
两个表“挤压”在一起。
\documentclass{article}
\usepackage{multirow,threeparttable}
\renewcommand\TPTtagStyle{\textit}
\usepackage{booktabs,subcaption}
\captionsetup[subtable]{skip=0.25\baselineskip} % optional
\begin{document}
\begin{table}[hbtp]
\begin{threeparttable}
%% Part 1 of 3: the caption
\caption{Participation Rates by Demographic Group}
\label{tab:participation_rates}
%% Part 2 of 3: the tabular-like structure
\begin{tabular}{@{}c@{}} % dummy "outer" tabular env.
\begin{minipage}{\textwidth}
\begin{subtable}[b]{0.48\textwidth}
\caption*{First Order Rates}
\begin{tabular}{@{} llcc @{}}
\toprule
& & \multicolumn{2}{c@{}}{mother's education} \\
\cmidrule(l){3-4}
& & hs\slash less\tnote{a} & coll\slash more \\
\midrule
\multirow{2}{*}{single\tnote{b}}
& black & 0.7983 & 0.6165 \\
& white & 0.6105 & 0.4144 \\
\addlinespace
\multirow{2}{*}{married\tnote{c}}
& black & 0.3286 & 0.1946 \\
& white & 0.1938 & 0.1118 \\
\bottomrule
\end{tabular}
\end{subtable}%
\hfill
\begin{subtable}[b]{0.48\textwidth}
\caption*{Second Order Rates}
\raggedleft % flush to right-hand edge of text block
\begin{tabular}{@{} llcc @{}}
\toprule
& & \multicolumn{2}{c@{}}{mother's education} \\
\cmidrule(l){3-4}
& & hs\slash less\tnote{a} & coll\slash more \\
\midrule
\multirow{2}{*}{single\tnote{b}}
& black & 0.6502 & 0.4230 \\
& white & 0.4547 & 0.2695 \\
\addlinespace
\multirow{2}{*}{married\tnote{c}}
& black & 0.2789 & 0.1438 \\
& white & 0.1562 & 0.0645 \\
\bottomrule
\end{tabular}
\end{subtable}
\end{minipage}
\end{tabular} % end of dummy "outer" tabular env.
%% Part 3 of 3: the tablenotes environment
\smallskip
\footnotesize
\begin{tablenotes}[flushleft]
\item[a] Some notes \dots
\item[b] Some more notes \dots
\item[c] Still more notes \dots
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}