我想将两个表格并排放置,下面提供了示例代码。如何在一个表格环境中的 LaTeX 中为两个表格添加单独的标题?
\documentclass{article}
\begin{document}
\begin{tabular}{ll}
\begin{tabular}{ccc}
A & B & C \\
\cline{1-3}
1 & 2 & 3 \\
\cline{1-3}
C & B & A \\
\end{tabular}
&
\begin{tabular}{ccc}
D & E & F \\
\cline{1-3}
4 & 5 & 6 \\
\cline{1-3}
F & E & D \\
\end{tabular}
\end{tabular}
\end{document}
答案1
用于tabularx
外表及使用table
环境:
\documentclass{article}
\usepackage[skip=1ex]{caption}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table}[htb]
\begin{tabularx}{\linewidth}{CC}
\caption{The first table}
\begin{tabular}{ccc}
A & B & C \\
\cline{1-3}
1 & 2 & 3 \\
\cline{1-3}
C & B & A \\
\end{tabular}
&
\caption{The second table}
\begin{tabular}{ccc}
D & E & F \\
\cline{1-3}
4 & 5 & 6 \\
\cline{1-3}
F & E & D \\
\end{tabular}
\end{tabularx}
\end{table}
\end{document}
附录:tabular*
在某些情况下,当一个表比另一个表更宽并且比列宽更宽时,您可以手动适应外部表的列宽。因为这比tabularx
表格环境 更适合使用:
\documentclass{article}
\usepackage[skip=1ex]{caption}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{table*}
\begin{tabular*}{\linewidth}{C{\dimexpr0.3\linewidth-2\tabcolsep}
C{\dimexpr0.7\linewidth-2\tabcolsep}}
\caption{The first table}
\begin{tabular}{ccc}
\hline
A & B & C \\
\hline
1 & 2 & 3 \\
C & B & A \\
\hline
\end{tabular}
&
\caption{The second table}
\begin{tabular}{*{14}{c}}
\hline
D & E & F & G & H & I & J & D & E & F & G & H & I & J \\
\hline
4 & 5 & 6 & 7 & 8 & 9 & 0 & 4 & 5 & 6 & 7 & 8 & 9 & 0 \\
J & I & H & G & F & E & D & J & I & H & G & F & E & D \\
\hline
\end{tabular}
\end{tabular*}
\end{table*}
\lipsum\lipsum
\end{document}
这使:
答案2
通过minipages
和,captionof
您可以实现以下目标:
\documentclass{article}
\usepackage{capt-of}
\begin{document}
\noindent
\begin{minipage}{0.5\textwidth}
\centering
\begin{tabular}{ccc}
A & B & C \\
\cline{1-3}
1 & 2 & 3 \\
\cline{1-3}
C & B & A \\
\end{tabular}
\captionof{table}{My first caption}
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\centering
\begin{tabular}{ccc}
D & E & F \\
\cline{1-3}
4 & 5 & 6 \\
\cline{1-3}
F & E & D \\
\end{tabular}
\captionof{table}{My second caption}
\end{minipage}
\end{document}
答案3
您可以使用该floatrow
包:
\documentclass{article}
\usepackage{caption}
\usepackage{floatrow}
\begin{document}
\begin{table}
\captionsetup{justification=raggedright}
\floatsetup{captionskip=2pt}
\begin{floatrow}
\ttabbox[1.4\FBwidth]{\caption{A First Table}}{\begin{tabular}{ccc}
A & B & C \\
\cline{1-3}
1 & 2 & 3 \\
\cline{1-3}
C & B & A \\
\end{tabular}}
\ttabbox[1.4\FBwidth]{\caption{A Second Table}}{\begin{tabular}{ccc}
D & E & F \\
\cline{1-3}
4 & 5 & 6 \\
\cline{1-3}
F & E & D \\
\end{tabular}}
\end{floatrow}
\end{table}
\end{document}