\documentclass[12pt]{article}
\title{Untitled Document}
\author{Your Name}
\date{\today}
\begin{document}
\maketitle
\begin{table}[!ht]
\caption{xxx (ML2)}
\label{tab:4}
\centering
\begin{tabular}{*{4}{|l}|} \hline
\diagbox[width=10em]{given}{predicted}&
1 & 0 \\ \hline
1 & (TP) & (FN) \\ \hline
0 & (FP) & (TN) \\ \hline
\end{tabular}
\end{table}
\begin{table}[!ht]
\caption{yyy (Alg1)}
\label{tab:3}
\centering
\begin{tabular}{*{4}{|l}|} \hline
\diagbox[width=10em]{given}{predicted}&
1 & 0 \\ \hline
1 & (TP) & (FN) \\ \hline
0 & (FP) & (TN) \\ \hline
\end{tabular}
\end{table}
\end{document}
我怎样才能将两个表格放在一个表格中。我要提交一篇只有 4 页的论文,因此我必须节省空间。提前感谢您的支持。干杯
答案1
您将表格放在minipages
相同的table
环境中,以便它们并排排版。
但是,目前的表格太宽,难以阅读,因此我提供了您最初的尝试和我的尝试。请自行选择(并且永远不要再使用\diagbox
)。
\documentclass[12pt]{article}
\usepackage{booktabs}
\usepackage{diagbox}
\title{Untitled Document}
\author{Your Name}
\date{\today}
\begin{document}
\maketitle
\begin{table}[!htp]
\begin{minipage}{0.5\textwidth}
\centering
\caption{xxx (ML2)}
\label{tab:4}
\begin{tabular}{@{}ccc@{}}
\toprule
given & \multicolumn{2}{c@{}}{predicted} \\
\cmidrule(l){2-3}
& 1 & 0 \\
\midrule
1 & (TP) & (FN) \\
0 & (FP) & (TN) \\
\bottomrule
\end{tabular}
\end{minipage}\hfill
\begin{minipage}{0.5\textwidth}
\centering
\caption{yyy (Alg1)}
\label{tab:3}
\centering
\begin{tabular}{*{4}{|l}|} \hline
\diagbox[width=10em]{given}{predicted}&
1 & 0 \\ \hline
1 & (TP) & (FN) \\ \hline
0 & (FP) & (TN) \\ \hline
\end{tabular}
\end{minipage}
\end{table}
\end{document}
如果实际的表格高度不同,你可能需要使用
\begin{minipage}[t]{0.5\textwidth}
并且,如果它们的宽度也不同,您可能需要调整 s 的宽度比例minipage
。
答案2
\documentclass[12pt]{article}
\usepackage{showframe}
\usepackage{diagbox}
\usepackage{lipsum}
\title{Untitled Document}
\author{Your Name}
\date{\today}
\begin{document}
\maketitle
\lipsum[1]
\begin{table}[htbp]
\begin{minipage}{.5\linewidth}
\caption{xxx (ML2)}
\label{tab:4}
\centering
\begin{tabular}{*{4}{|l}|}
\hline
\diagbox[width=9em]{given}{predicted} &
1 & 0 \\ \hline
1 & (TP) & (FN) \\ \hline
0 & (FP) & (TN) \\ \hline
\end{tabular}
\end{minipage}
\begin{minipage}{.5\linewidth}
\caption{yyy (Alg1)}
\label{tab:3}
\centering
\begin{tabular}{*{4}{|l}|}
\hline
\diagbox[width=9em]{given}{predicted} &
1 & 0 \\ \hline
1 & (TP) & (FN) \\ \hline
0 & (FP) & (TN) \\ \hline
\end{tabular}
\end{minipage}
\end{table}
\lipsum[1]
\end{document}
答案3
您可以使用该floatrow
包来实现此目的:
\documentclass[12pt]{article}
\usepackage{diagbox}
\usepackage{floatrow}
\title{Untitled Document}
\author{Your Name}
\date{\today}
\begin{document}
\maketitle
\begin{table}[!ht]
\centering
\begin{floatrow}
\ttabbox{\caption{xxx (ML2)}
\label{tab:4}}
{\begin{tabular}{*{4}{|l}|} \hline
\diagbox[width=10em]{given}{predicted}&
1 & 0 \\ \hline
1 & (TP) & (FN) \\ \hline
0 & (FP) & (TN) \\ \hline
\end{tabular}}
%
\ttabbox{\caption{yyy (Alg1)}\label{tab:3}}
{\begin{tabular}{*{4}{|l}|} \hline
\diagbox[width=10em]{given}{predicted}&
1 & 0 \\ \hline
1 & (TP) & (FN) \\ \hline
0 & (FP) & (TN) \\ \hline
\end{tabular}}
\end{floatrow}
\end{table}
\end{document}
答案4
您可以让它们均匀分布在页面宽度上。虽然minipage
s 是将标题和表格放在一起,但它们minipage
可以并排放置。然后,\hspace{\fill}
用作填充符,在表格和边距之间添加所需的空白。
\documentclass[12pt]{article}
\usepackage{diagbox}
\usepackage{tabularx}
\usepackage{showframe}
\renewcommand*{\ShowFrameLinethickness}{0.2pt}
\renewcommand*{\ShowFrameColor}{\color{blue}}
\title{Untitled Document}
\author{Your Name}
\date{\today}
\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\maketitle
\begin{table}[!ht]
\hspace{\fill}%
\begin{minipage}{0.4\linewidth}
\centering
\caption{xxx (ML2)}\label{tab:4}
\begin{tabularx}{\linewidth}{|c|*2{X|}}
\hline
\diagbox[width=6em]{given}{pred.} & 1 & 0 \\
\hline
1 & (TP) & (FN) \\ \hline
0 & (FP) & (TN) \\ \hline
\end{tabularx}%
\end{minipage}%
\hspace{\fill}%
\begin{minipage}{0.4\linewidth}
\centering
\caption{yyy (Alg1)}\label{tab:3}
\begin{tabularx}{\linewidth}{|c|*2{X|}} \hline
\diagbox[width=6em]{given}{pred.}&
1 & 0 \\ \hline
1 & (TP) & (FN) \\ \hline
0 & (FP) & (TN) \\ \hline
\end{tabularx}%
\end{minipage}%
\hspace*{\fill}%
\end{table}
\end{document}