答案1
编辑:
考虑到 OP 评论说表格宽度应等于\textwidth
。为此使用tabularx
表格环境:
使用makecell
(for\Xhline{...}
和makegapedcells
)和tabularx
包:
\documentclass{article}
\usepackage{makecell, tabularx}
\begin{document}
\begin{table}[htb]
\centering
\setcellgapes{4pt}
\makegapedcells
\caption{Caption}
\label{tab:example}
\begin{tabularx}{\linewidth}{|*{4}{>{\centering\arraybackslash}X|} }
\Xhline{1.2pt}
\multicolumn{2}{|c|}{A} & \multicolumn{2}{c|}{B} \\
\Xhline{0.8pt}
Class & Number & Class & Number \\ \hline
& & & \\ \hline
& & & \\
\Xhline{1.2pt}
\end{tabularx}
\end{table}
\end{document}
或不使用垂直线并使用包装 booktabs
:
\documentclass{article}
\usepackage{booktabs, tabularx}
\begin{document}
\begin{table}[htb]
\centering
\caption{Caption}
\label{tab:example}
\begin{tabularx}{\linewidth}{ *{4}{>{\centering\arraybackslash}X} }
\toprule
\multicolumn{2}{c}{A} & \multicolumn{2}{c}{B} \\
\cmidrule(r){1-2}
\cmidrule(l){3-4}
Class & Number & Class & Number \\
\midrule
aaa & bbb & ccc & ddd \\
aaa & bbb & ccc & ddd \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}