subtable
我正在尝试使用from生成三个子表\usepackage{subcaption}
,但仍然收到失败消息。有人能帮忙吗?这是我的全部代码:
\documentclass[12pt]{article}
\usepackage{array, boldline}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{booktabs}
\usepackage{subcaption}
\begin{document}
\begin{table}
\caption{Demand and Supply}
\begin{subtable}
\caption{Market A}
\begin{tabular}{ P{50mm} P{50mm} P{50mm} }
\toprule
Price & Demand & Supply \\
\midrule
35 & 200 & 900 \\
30 & 400 & 750 \\
\bottomrule
\end{tabular}
\end{subtable}
\begin{subtable}
\caption{Market B}
\begin{tabular}{ P{50mm} P{50mm} P{50mm} }
\toprule
Price & Demand & Supply \\
\midrule
35 & 300 & 800 \\
30 & 500 & 650 \\
\bottomrule
\end{tabular}
\end{subtable}
\end{table}
\end{document}
答案1
您需要为 s 指定宽度subtable
。但是,您的列非常宽。tabularx
您可以在给定约束的情况下最大化列宽。(编辑:删除了多余的居中,正如 Mico 所指出的那样。)
\documentclass[12pt]{article}
\usepackage{array, boldline}
\newcolumntype{Q}{>{\centering\arraybackslash}X}
\usepackage{booktabs}
\usepackage{subcaption}
\usepackage{tabularx}
\begin{document}
\begin{table}
\centering
\caption{Demand and Supply}
\begin{subtable}{0.45\textwidth}
\caption{Market A}
\begin{tabularx}{\textwidth}{QQQ}
\toprule
Price & Demand & Supply \\
\midrule
35 & 200 & 900 \\
30 & 400 & 750 \\
\bottomrule
\end{tabularx}
\end{subtable}\qquad
\begin{subtable}{0.45\textwidth}
\caption{Market B}
\begin{tabularx}{\textwidth}{QQQ}
\toprule
Price & Demand & Supply \\
\midrule
35 & 300 & 800 \\
30 & 500 & 650 \\
\bottomrule
\end{tabularx}
\end{subtable}
\end{table}
\end{document}
或者没有的版本\centering
(非常感谢@Mico)。
\documentclass[12pt]{article}
\usepackage{array, boldline}
\newcolumntype{Q}{>{\centering\arraybackslash}X}
\usepackage{booktabs}
\usepackage{subcaption}
\usepackage{tabularx}
\begin{document}
\begin{table}
\caption{Demand and Supply}
\quad\begin{subtable}{0.45\textwidth}
\caption{Market A}
\begin{tabularx}{\textwidth}{QQQ}
\toprule
Price & Demand & Supply \\
\midrule
35 & 200 & 900 \\
30 & 400 & 750 \\
\bottomrule
\end{tabularx}
\end{subtable}\hfill
\begin{subtable}{0.45\textwidth}
\caption{Market B}
\begin{tabularx}{\textwidth}{QQQ}
\toprule
Price & Demand & Supply \\
\midrule
35 & 300 & 800 \\
30 & 500 & 650 \\
\bottomrule
\end{tabularx}
\end{subtable}\quad\mbox{}
\end{table}
\end{document}
答案2
您可能想要使用\subcaptionbox
:
\documentclass[12pt]{article}
\usepackage{array, boldline}
\usepackage{booktabs}
\usepackage{subcaption}
\begin{document}
\begin{table}
\caption{Demand and Supply}
\subcaptionbox{Market A}{%
\setlength{\tabcolsep}{0pt}%
\begin{tabular}{ @{} *{3}{wc{0.16\textwidth}} @{} }
\toprule
Price & Demand & Supply \\
\midrule
35 & 200 & 900 \\
30 & 400 & 750 \\
\bottomrule
\end{tabular}%
}\hfill
\subcaptionbox{Market B}{%
\setlength{\tabcolsep}{0pt}%
\begin{tabular}{ @{} *{3}{wc{0.16\textwidth}} @{} }
\toprule
Price & Demand & Supply \\
\midrule
35 & 300 & 800 \\
30 & 500 & 650 \\
\bottomrule
\end{tabular}%
}
\end{table}
\end{document}
我固定了宽度并使用wc{0.16\textwidth}
:您有六列,并且设置\tabcolsep
为零,宽度应该是0.16666\textwidth
,但我在表格之间留了一些空间。