如何将这 4 个迷你表格从垂直格式转换为 2 x 2 框架格式?

如何将这 4 个迷你表格从垂直格式转换为 2 x 2 框架格式?

我喜欢将以下四个表格转换为 2 x2 格式,而不是垂直显示它们。另外,图形环境将它们标记为图,这并不理想,因为我想将它们标记为表格。请帮忙。

\documentclass[final,1p,12pt]{elsarticle}
\usepackage{subcaption}
\usepackage{multirow}
\usepackage{array}
\begin{document}
\begin{figure}
    \centering
    \caption{Accuracy calculations under different classifiers}
    
    \begin{subfigure}{\textwidth}
        \centering
        \caption{Decision Tree}
        \begin{tabular}{|c|c|c|c|c|}
            \hline
            Identity & Precision & Recall & f1-score & Support \\
            \hline
             User1 & 0.99 & 0.99 & 0.99 & 12889 \\
            \hline% Add data rows here
            User2& 0.99 & 0.99 & 0.99 &23646 \\
            \hline
            User3 & 0.99 & 0.99 & 0.99 &12076 \\
            \hline
            User4&0.99 & 0.99 & 0.99 &11345 \\
            \hline
            User5& 0.99 & 0.99 & 0.99 &10765 \\
            \hline
            User6& 0.99 & 0.99 & 0.99 &10244 \\
            \hline
        \end{tabular}
    \end{subfigure}
    
    \vspace{1em}
    
    \begin{subfigure}{\textwidth}
        \centering
        \caption{KNN}
        \begin{tabular}{|c|c|c|c|c|}
            \hline
            Identity & Precision & Recall & f1-score & Support \\
            \hline
            User1&0.89 &0.95 &0.93 &12889 \\
            \hline
            User2&0.85 &0.88 & 0.87 &23646 \\
            \hline
            User3& 0.93&0.98 &0.95 & 12076\\
            \hline
            User4& 0.89& 0.78 &0.84 &  11345 \\
            \hline
            User5&0.91 & 0.88 &0.90 &10765 \\
            \hline
            User6&0.87 &0.82 &0.85 &10244 \\
            \hline
        \end{tabular}
    \end{subfigure}
    
    \vspace{1em}
    
    \begin{subfigure}{\textwidth}
        \centering
        \caption{SVM}
        \begin{tabular}{|c|c|c|c|c|}
            \hline
            Identity & Precision & Recall & f1-score & Support \\
            \hline
            User1&0.82&0.88&0.85 &12889 \\
            \hline
            User2&0.68 &0.70 & 0.70&23646 \\
            \hline
            User3& 0.81&0.95 &0.87 & 12076\\
            \hline
            User4& 0.72& 0.59 &0.65 &  11345 \\
            \hline
            User5&0.77 & 0.72 &0.75&10765 \\
            \hline
            User6&0.62 &0.56 &0.59 &10244 \\
            \hline
        \end{tabular}
    \end{subfigure}
     \vspace{1em}
    
    \begin{subfigure}{\textwidth}
        \centering
        \caption{Logistic Regression}
        \begin{tabular}{|c|c|c|c|c|}
            \hline
            Identity & Precision & Recall & f1-score & Support \\
            \hline
            User1&0.62 & 0.73 &0.67&12889 \\
            \hline
            User2& 0.45 & 0.46 & 0.45 &23646 \\
            \hline
            User3& 0.70&0.79 & 0.74 & 12076\\
            \hline
            User4& 0.54& 0.46 &0.50 &  11345 \\
            \hline
            User5&0.63 & 0.64 &0.64 &10765 \\
            \hline
            User6&0.46 &0.33 &0.39&10244 \\
            \hline
        \end{tabular}
    \end{subfigure}
    \end{figure}
    \end{document} 

期望的输出类似于 期望输出

答案1

像这样吗?

在此处输入图片描述

相对于 OP 的示例代码,一些主要的变化如下:

  • 将的所有四个实例更改subfiguresubtable并将 的实例更改figuretable
  • 将全部四个实例更改{\textwidth}{0.475\textwidth}
  • 在标题单元格中使用缩写(以使列变窄)
  • 减少值\tabcolsep(影响空白填充的数量)
  • 切换到\small相对字体大小(字体大小线性减少 10%)
  • 消除子表 a/b 和 c/d 之间的空行,因为空行会导致换行
  • \vspace{1em}子表 a/b 和 c/d 之间的变更\hfill

\documentclass[final,1p,12pt]{elsarticle}
\usepackage{array,subcaption}

\begin{document}
\begin{table}
\small
\setlength\tabcolsep{3pt} % default value: 6pt
\caption{Accuracy calculations under different classifiers}

    \begin{subtable}{0.475\textwidth}
        \centering
        \caption{Decision Tree}
        \begin{tabular}{|c|c|c|c|c|}
            \hline
            Ident. & Prec. & Recall & f1-sc. & Supp. \\
            \hline
            User1 & 0.99 & 0.99 & 0.99 & 12889 \\
            \hline% Add data rows here
            User2& 0.99 & 0.99 & 0.99 &23646 \\
            \hline
            User3 & 0.99 & 0.99 & 0.99 &12076 \\
            \hline
            User4&0.99 & 0.99 & 0.99 &11345 \\
            \hline
            User5& 0.99 & 0.99 & 0.99 &10765 \\
            \hline
            User6& 0.99 & 0.99 & 0.99 &10244 \\
            \hline
        \end{tabular}
    \end{subtable}%
    \hfill
    \begin{subtable}{0.475\textwidth}
        \centering
        \caption{KNN}
        \begin{tabular}{|c|c|c|c|c|}
            \hline
            Ident. & Prec. & Recall & f1-sc. & Supp. \\
            \hline
            User1&0.89 &0.95 &0.93 &12889 \\
            \hline
            User2&0.85 &0.88 & 0.87 &23646 \\
            \hline
            User3& 0.93&0.98 &0.95 & 12076\\
            \hline
            User4& 0.89& 0.78 &0.84 &  11345 \\
            \hline
            User5&0.91 & 0.88 &0.90 &10765 \\
            \hline
            User6&0.87 &0.82 &0.85 &10244 \\
            \hline
        \end{tabular}
    \end{subtable}

    \vspace{2ex}

    \begin{subtable}{0.475\textwidth}
        \centering
        \caption{SVM}
        \begin{tabular}{|c|c|c|c|c|}
            \hline
            Ident. & Prec. & Recall & f1-sc. & Supp. \\
            \hline
            User1&0.82&0.88&0.85 &12889 \\
            \hline
            User2&0.68 &0.70 & 0.70&23646 \\
            \hline
            User3& 0.81&0.95 &0.87 & 12076\\
            \hline
            User4& 0.72& 0.59 &0.65 &  11345 \\
            \hline
            User5&0.77 & 0.72 &0.75&10765 \\
            \hline
            User6&0.62 &0.56 &0.59 &10244 \\
            \hline
        \end{tabular}
    \end{subtable}%
    \hfill
    \begin{subtable}{0.475\textwidth}
        \centering
        \caption{Logistic Regression}
        \begin{tabular}{|c|c|c|c|c|}
            \hline
            Ident. & Prec. & Recall & f1-sc. & Supp. \\
            \hline
            User1&0.62 & 0.73 &0.67&12889 \\
            \hline
            User2& 0.45 & 0.46 & 0.45 &23646 \\
            \hline
            User3& 0.70&0.79 & 0.74 & 12076\\
            \hline
            User4& 0.54& 0.46 &0.50 &  11345 \\
            \hline
            User5&0.63 & 0.64 &0.64 &10765 \\
            \hline
            User6&0.46 &0.33 &0.39&10244 \\
            \hline
        \end{tabular}
    \end{subtable}
    
\end{table}
\end{document} 

相关内容