我用来subcaption
并排布局两个不同宽度的表格,但我不明白如何预先知道表格的宽度。我应该用什么来代替这些*
?
\begin{table}[p]
\centering
\begin{subtable}{*}
\begin{tabular}{rccc}
\toprule
& {\bf\small no}
& {\bf\small informally}
& {\bf\small formally} \\ \midrule
{\bf\small beginners} & {\bf 4} & 3 & 1 \\
{\bf\small non-beginners} & 0 & 0 & {\bf 12} \\
{\bf\small total} & 4 & 3 & {\bf 13} \\ \bottomrule
\end{tabular}
\caption{Q1: Have you studied music?}
\end{subtable}
\qquad
\begin{subtable}{*}
\begin{tabular}{ccc}
\toprule
{\bf\small no}
& {\bf\small one}
& {\bf\small more} \\ \midrule
{\bf 6} & 2 & 0 \\
1 & {\bf 6} & 5 \\
{\bf 7} & {\bf 8} & 5 \\ \bottomrule
\end{tabular}
\caption{Q2: Do you play a musical instrument?}
\end{subtable}
\end{table}
答案1
您可以改用\subcaptionbox
其宽度等于内容宽度(除非通过可选参数进行修改):
\documentclass{article}
\usepackage{array}
\usepackage{subcaption}
\usepackage{booktabs}
\begin{document}
\begin{table}[p]
\centering
\subcaptionbox{Q1: Have you studied music?}{%
\begin{tabular}{>{\bfseries\small}rccc}
\toprule
& \bfseries\small no
& \bfseries\small informally
& \bfseries\small formally \\ \midrule
beginners & \bfseries 4 & 3 & 1 \\
non-beginners & 0 & 0 & \bfseries 12 \\
total & 4 & 3 & \bfseries 13 \\ \bottomrule
\end{tabular}}\qquad
\subcaptionbox{Q2: Do you play a musical instrument?}{%
\begin{tabular}{>{\bfseries\small}ccc}
\toprule
no
& \bfseries\small one
& \bfseries\small more \\ \midrule
6 & 2 & 0 \\
1 & \bfseries 6 & 5 \\
7 & \bfseries 8 & 5 \\ \bottomrule
\end{tabular}}
\end{table}
\end{document}
结果:
评论
\bf
已过时,请改用\bfseries
。- 由于每个单元格形成一个组,因此不需要明确的分组。
- 使用包
>{...}
中的语法,array
您可以>{\bfseries\small}
将这些设置应用于整个列。