2
\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}

How can I include both tables in one table. I'm going to submit a paper with only 4 pages and therefore I have to save space. Thank you in advance for your support. Cheers

1
  • delete \end{table} \begin{table}[!ht] from the middle of your example Commented Sep 11, 2022 at 13:46

4 Answers 4

3

You place the tables in minipages in the same table environment, so they're typeset side by side.

However, in their current status the tables are too wide and difficult to read, so I present your original attempt and mine. Take your pick (and never again use \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}

enter image description here

If the actual tables have different heights, you may want to use

\begin{minipage}[t]{0.5\textwidth}

and, if they also have different widths you may need to adjust the proportion in the width of the minipages.

1
\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}

enter image description here

1

You can use the floatrow package for that:

    \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} 

enter image description here

1

You can have them equally distributed over the page width. While minipages are to keep captions and tables together, each minipage can be placed side by side. Then, \hspace{\fill} is used as a filler adding required white space between tables and margins.

enter image description here

\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}
1
  • Thank you, that worked for me !! You guys are amazing ...
    – maxmin
    Commented Sep 24, 2022 at 23:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .