0

I have searched stack exchange for answer to how I can create a beamer having 2-tables with many columns side-by-side, all the answers I am getting refers to tables with few columns.

Currently I have two tables with 8-columns each, formatted in an ieeetran document class that I want to put in one slide in my beamer document side-by-side.

MSE for code in my ieeetran document:

\documentclass{ieeetran}
\usepackage{rotating}
\usepackage{booktabs, makecell, multirow}
\usepackage{xparse}
\NewExpandableDocumentCommand\mcc{O{1}m}
    {\multicolumn{#1}{c}{#2}}
\usepackage{siunitx}

 \begin{document}
  \begin{table}[ht]
\sisetup{table-number-alignment=center}
    \caption{Confusion matrix normalized}
    \label{tab1}
    \settowidth\rotheadsize{\textbf{Predicted}}
    \centering
    \begin{tabular}{*{2}{>{\bfseries}l} *{6}{S[table-format=1.2]} }
    \toprule
    & & \mcc[6]{\textbf{Actual}} \\
    \cmidrule{3-8}
    & & {\textbf{Class1}} & {\textbf{Class2}} & {\textbf{Class3}}
    & {\textbf{Class4}} & {\textbf{Class5}} & {\textbf{Precision}}\\
    \midrule
    \multirow{5}{*}{\rothead{Predicted}}
        & Class1 & 0.34 & 0.13 & 0.17 & 0.09 & 0.27 & 0.59 \\
        & Class2 & 0.29 & 0.17 & 0.21 & 0.02 & 0.33 & 0.05 \\
        & Class3 & 0.20 & 0.16 & 0.26 & 0.16 & 0.21 & 0.22 \\
        & Class4 & 0.12 & 0.15 & 0.22 & 0.36 & 0.15 & 0.65 \\
        & Class5 & 0.34 & 0.13 & 0.10 & 0.17 & 0.26 & 0.01 \\
    \midrule
        & Recall & 0.35 & 0.05 & 0.03 & 0.78 & 0.16 & \\
    \bottomrule
    \end{tabular}
\end{table}

\begin{table}[ht]
        \caption{Confusion matrix actual class values}
        \label{tab2}
        \settowidth\rotheadsize{\textbf{Predicted}}
        \centering
        \begin{tabular}{*{2}{>{\bfseries}l} *{5}{S[table-format=4.0]}S[table-format=1.2] }
        \toprule
        & & \mcc[6]{\textbf{Actual}} \\
        \cmidrule{3-8}
        & & {\textbf{Class1}} & {\textbf{Class2}} & {\textbf{Class3}}
        & {\textbf{Class4}} & {\textbf{Class5}} & {\textbf{Precision}}\\
        \midrule
        \multirow{5}{*}{\rothead{Predicted}}
            & Class1 & 5007 & 1896 & 2437 & 1314 & 3947 & 0.59 \\
            & Class2 & 409 & 218 & 286 & 27 & 458 & 0.05 \\
            & Class3 & 1688 & 1365 & 2159 & 1346 & 1759 & 0.22 \\
            & Class4 & 2386 & 3093 & 4521 & 7323 & 2978 & 0.65 \\
            & Class5 & 311 & 113 & 93 & 154 & 233 & 0.01 \\
        \midrule
            &Recall & {0.35} & {0.05} & {0.03} & {0.78} & {0.16} & \\
        \bottomrule
        \end{tabular}
    \end{table}
    
\end{document}

enter image description here How do I add to a one slide side-by-side in beamer? If not possible then top-bottom.

1
  • 1
    Why not 2 slides where the values inside the table change from one slide to the next? There's great duplication in the two tables, and having that amount of information on a single slide seems inefficient.
    – Werner
    Mar 2, 2021 at 19:00

1 Answer 1

1

You may liked:

enter image description here

\documentclass{beamer}
    \setbeamertemplate{caption}[numbered]
    \setbeamerfont{caption}{size=\scriptsize}
%----

\usepackage{rotating}
\usepackage{booktabs, makecell, multirow}
\usepackage{xparse}  % it is not required at the latest version
\NewExpandableDocumentCommand\mcc{O{1}m}
    {\multicolumn{#1}{c}{#2}}
\NewExpandableDocumentCommand\mcl{O{1}m}
    {\multicolumn{#1}{l}{#2}}
\usepackage{siunitx}

\begin{document}
\begin{frame}[fragile]
\frametitle{Two tables}
    \begin{columns}[T]
    \begin{column}{0.52\textwidth}
\begin{table}
\scriptsize
    \setlength\tabcolsep{0pt}
    \settowidth\rotheadsize{ \textbf{Predicted} }
\caption{Confusion matrix normalized}
\label{tab1}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} *{2}{>{\bfseries}l} 
                                                    *{6}{S[table-format=1.2]} }
        \toprule
    &           & \mcc[6]{\textbf{Actual}}                              \\
        \cmidrule{3-8}
    &           & {\textbf{C 1}} & {\textbf{C 2}} & {\textbf{C 3}}
                & {\textbf{C 4}} & {\textbf{C 5}} & {\textbf{Precision}}   \\
        \midrule
    \multirow{5}{*}{\rothead{Predicted}}
    & C 1    & 0.34  & 0.13  & 0.17  & 0.09  & 0.27  & 0.59  \\
    & C 2    & 0.29  & 0.17  & 0.21  & 0.02  & 0.33  & 0.05  \\
    & C 3    & 0.20  & 0.16  & 0.26  & 0.16  & 0.21  & 0.22  \\
    & C 4    & 0.12  & 0.15  & 0.22  & 0.36  & 0.15  & 0.65  \\
    & C 5    & 0.34  & 0.13  & 0.10  & 0.17  & 0.26  & 0.01  \\
        \midrule
\mcc [2]{Recall}
            & 0.35  & 0.05  & 0.03  & 0.78  & 0.16  &       \\
    \bottomrule
    \end{tabular*}
\end{table}
    \end{column}
    \begin{column}{0.55\textwidth}
\begin{table}
\scriptsize
    \setlength\tabcolsep{0pt}
    \settowidth\rotheadsize{ \textbf{Predicted} }
\caption{Confusion matrix actual class values}
\label{tab2}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} *{2}{>{\bfseries}l} 
                                       *{5}{S[table-format=4.0]}
                                            S[table-format=1.2] }
        \toprule
    &           & \mcc[6]{\textbf{Actual}}                              \\
        \cmidrule{3-8}
    &           & {\textbf{C 1}} & {\textbf{C 2}} & {\textbf{C 3}}
                & {\textbf{C 4}} & {\textbf{C 5}} & {\textbf{Precision}}   \\
        \midrule
    \multirow{5}{*}{\rothead{Predicted}}
    & C 1    & 5007  & 1896  & 2437  & 1314  & 3947  & 0.59  \\
    & C 2    & 409   & 218   & 286   & 27    & 458   & 0.05  \\
    & C 3    & 1688  & 1365  & 2159  & 1346  & 1759  & 0.22  \\
    & C 4    & 2386  & 3093  & 4521  & 7323  & 2978  & 0.65  \\
    & C 5    & 311   & 113   & 93    & 154   & 233   & 0.01  \\
        \midrule
\mcc [2]{Recall}
            &{0.35} &{0.05} &{0.03} &{0.78} &{0.16} &       \\
        \bottomrule
    \addlinespace
\mcl[8]{\emph{Note}: \textbf{C} stands for \textbf{Class}.}
    \end{tabular*}
\end{table}
    \end{column}
    \end{columns}
\end{frame}
\end{document}

Edit: or the following small variation of the above proposition:

\documentclass{beamer}
    \setbeamertemplate{caption}[numbered]
    \setbeamerfont{caption}{size=\scriptsize}
%----

\usepackage{rotating}
\usepackage{booktabs, makecell, multirow}
\NewExpandableDocumentCommand\mcc{O{1}m}
    {\multicolumn{#1}{c}{#2}}
\NewExpandableDocumentCommand\mcl{O{1}m}
    {\multicolumn{#1}{l}{#2}}
\usepackage{siunitx}

\begin{document}
\begin{frame}[fragile]
\frametitle{Two tables (second variant)}
    \begin{columns}[T]
    \begin{column}{0.52\textwidth}
\begin{table}
\scriptsize
    \setlength\tabcolsep{0pt}
    \settowidth\rotheadsize{ \textbf{Predicted} }
\caption{Confusion matrix normalized}
\label{tab1}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} *{2}{>{\bfseries}l} 
                                                    *{6}{S[table-format=1.2]} }
        \toprule
    &           & \mcc[6]{\textbf{Actual}}                              \\
        \cmidrule{3-8}
    &           & {\textbf{C 1}} & {\textbf{C 2}} & {\textbf{C 3}}
                & {\textbf{C 4}} & {\textbf{C 5}} & {\textbf{P}}   \\
        \midrule
    \multirow{5}{*}{\rothead{Predicted}}
    & C 1    & 0.34  & 0.13  & 0.17  & 0.09  & 0.27  & 0.59  \\
    & C 2    & 0.29  & 0.17  & 0.21  & 0.02  & 0.33  & 0.05  \\
    & C 3    & 0.20  & 0.16  & 0.26  & 0.16  & 0.21  & 0.22  \\
    & C 4    & 0.12  & 0.15  & 0.22  & 0.36  & 0.15  & 0.65  \\
    & C 5    & 0.34  & 0.13  & 0.10  & 0.17  & 0.26  & 0.01  \\
        \midrule
\mcc [2]{Recall}
            & 0.35  & 0.05  & 0.03  & 0.78  & 0.16  &       \\
    \bottomrule
    \end{tabular*}
\end{table}
    \end{column}
    \begin{column}{0.55\textwidth}
\begin{table}
\scriptsize
    \setlength\tabcolsep{0pt}
    \settowidth\rotheadsize{ \textbf{Predicted} }
\caption{Confusion matrix actual class values}
\label{tab2}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} *{2}{>{\bfseries}l} 
                                       *{5}{S[table-format=4.0]}
                                            S[table-format=1.2] }
        \toprule
    &           & \mcc[6]{\textbf{Actual}}                              \\
        \cmidrule{3-8}
    &           & {\textbf{C 1}} & {\textbf{C 2}} & {\textbf{C 3}}
                & {\textbf{C 4}} & {\textbf{C 5}} & {\textbf{P}}   \\
        \midrule
    \multirow{5}{*}{\rothead{Predicted}}
    & C 1    & 5007  & 1896  & 2437  & 1314  & 3947  & 0.59  \\
    & C 2    & 409   & 218   & 286   & 27    & 458   & 0.05  \\
    & C 3    & 1688  & 1365  & 2159  & 1346  & 1759  & 0.22  \\
    & C 4    & 2386  & 3093  & 4521  & 7323  & 2978  & 0.65  \\
    & C 5    & 311   & 113   & 93    & 154   & 233   & 0.01  \\
        \midrule
\mcc [2]{Recall}
            &{0.35} &{0.05} &{0.03} &{0.78} &{0.16} &       \\
        \bottomrule
    \addlinespace
\mcl[8]{\emph{Note}: \makecell[lt]{\textbf{C} stands for \textbf{Class}\\ and \textbf{P} for \textbf{Precision}.}}
    \end{tabular*}
\end{table}
    \end{column}
    \end{columns}
\end{frame}
\end{document}

second example

1
  • Thanks, really helpful.
    – arilwan
    Mar 3, 2021 at 10:30

You must log in to answer this question.

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