在每个表格上方/下方添加标题和说明

在每个表格上方/下方添加标题和说明

我正在尝试创建如下所示的 4 个表格:但是我想为每个表格添加一个标题tabular并在每个表格下方添加一个标题tabular

如果您对我该如何进行有任何建议那就太好了。

\begin{table}
    \centering

    \begin{tabular}{@{}cc|cc@{}}

    \multicolumn{1}{c}{} &\multicolumn{1}{c}{} &\multicolumn{2}{c}{Predicted} \\ 
    \multicolumn{1}{c}{} & 
    \multicolumn{1}{c|}{} & 
    \multicolumn{1}{c}{Yes} & 
    \multicolumn{1}{c}{No} \\ 
    \cline{2-4}
    \multirow[c]{2}{*}{\rotatebox[origin=tr]{90}{Actual}}
    & Yes  & 100 & 0   \\[1.5ex]
    & No  & 10   & 80 \\ 
    \cline{2-4}
    \end{tabular}
    \quad% ---------------------------
    \begin{tabular}{@{}cc|cc@{}}
    \multicolumn{1}{c}{} &\multicolumn{1}{c}{} &\multicolumn{2}{c}{Predicted} \\ 
    \multicolumn{1}{c}{} & 
    \multicolumn{1}{c|}{} & 
    \multicolumn{1}{c}{Yes} & 
    \multicolumn{1}{c}{No} \\ 
    \cline{2-4}
    \multirow[c]{2}{*}{\rotatebox[origin=tr]{90}{Actual}}
    & Yes  & 100 & 0   \\[1.5ex]
    & No  & 10   & 80 \\ 
    \cline{2-4}
    \end{tabular}

    \par\bigskip
    \begin{tabular}{@{}cc|cc@{}}
    \multicolumn{1}{c}{} &\multicolumn{1}{c}{} &\multicolumn{2}{c}{Predicted} \\ 
    \multicolumn{1}{c}{} & 
    \multicolumn{1}{c|}{} & 
    \multicolumn{1}{c}{Yes} & 
    \multicolumn{1}{c}{No} \\ 
    \cline{2-4}
    \multirow[c]{2}{*}{\rotatebox[origin=tr]{90}{Actual}}
    & Yes  & 100 & 0   \\[1.5ex]
    & No  & 10   & 80 \\ 
    \cline{2-4}
    \end{tabular}
    \quad% ---------------------------
    \begin{tabular}{@{}cc|cc@{}}
    \multicolumn{1}{c}{} &\multicolumn{1}{c}{} &\multicolumn{2}{c}{Predicted} \\ 
    \multicolumn{1}{c}{} & 
    \multicolumn{1}{c|}{} & 
    \multicolumn{1}{c}{Yes} & 
    \multicolumn{1}{c}{No} \\ 
    \cline{2-4}
    \multirow[c]{2}{*}{\rotatebox[origin=tr]{90}{Actual}}
    & Yes  & 100 & 0   \\[1.5ex]
    & No  & 10   & 80 \\ 
    \cline{2-4}
    \end{tabular}
    \end{table}

答案1

将每个tabular组件设置在 内minipage。如果 内的组件minipage高度不同,则可以使用 对齐它们\begin{minipage}[<align>]{<len>}(其中<align>可以是top 或bottom)。

在此处输入图片描述

\documentclass{article}

\usepackage{multirow,graphicx}

\begin{document}

\begin{table}
  \centering

  \begin{minipage}{.4\linewidth}
    \centering
    {\bfseries\strut Top left title}

    \begin{tabular}{@{}cc|cc@{}}
      \multicolumn{1}{c}{} &\multicolumn{1}{c}{} &\multicolumn{2}{c}{Predicted} \\ 
      \multicolumn{1}{c}{} & 
      \multicolumn{1}{c|}{} & 
      \multicolumn{1}{c}{Yes} & 
      \multicolumn{1}{c}{No} \\ 
      \cline{2-4}
      \multirow[c]{2}{*}{\rotatebox[origin=tr]{90}{Actual}}
      & Yes  & 100 & 0   \\[1.5ex]
      & No  & 10   & 80 \\ 
      \cline{2-4}
    \end{tabular}

    \caption{Top left caption}
  \end{minipage}%
  \quad % ----------------------------------
  \begin{minipage}{.4\linewidth}
    \centering
    {\bfseries\strut Top right title}

    \begin{tabular}{@{}cc|cc@{}}
      \multicolumn{1}{c}{} &\multicolumn{1}{c}{} &\multicolumn{2}{c}{Predicted} \\ 
      \multicolumn{1}{c}{} & 
      \multicolumn{1}{c|}{} & 
      \multicolumn{1}{c}{Yes} & 
      \multicolumn{1}{c}{No} \\ 
      \cline{2-4}
      \multirow[c]{2}{*}{\rotatebox[origin=tr]{90}{Actual}}
      & Yes  & 100 & 0   \\[1.5ex]
      & No  & 10   & 80 \\ 
      \cline{2-4}
    \end{tabular}
    \caption{Top right caption}
  \end{minipage}

  \bigskip

  \begin{minipage}{.4\linewidth}
    \centering
    {\bfseries\strut Bottom left title}

    \begin{tabular}{@{}cc|cc@{}}
      \multicolumn{1}{c}{} &\multicolumn{1}{c}{} &\multicolumn{2}{c}{Predicted} \\ 
      \multicolumn{1}{c}{} & 
      \multicolumn{1}{c|}{} & 
      \multicolumn{1}{c}{Yes} & 
      \multicolumn{1}{c}{No} \\ 
      \cline{2-4}
      \multirow[c]{2}{*}{\rotatebox[origin=tr]{90}{Actual}}
      & Yes  & 100 & 0   \\[1.5ex]
      & No  & 10   & 80 \\ 
      \cline{2-4}
    \end{tabular}
    \caption{Bottom left caption}
  \end{minipage}%
  \quad % ----------------------------------
  \begin{minipage}{.4\linewidth}
    \centering
    {\bfseries\strut Bottom right title}

    \begin{tabular}{@{}cc|cc@{}}
      \multicolumn{1}{c}{} &\multicolumn{1}{c}{} &\multicolumn{2}{c}{Predicted} \\ 
      \multicolumn{1}{c}{} & 
      \multicolumn{1}{c|}{} & 
      \multicolumn{1}{c}{Yes} & 
      \multicolumn{1}{c}{No} \\ 
      \cline{2-4}
      \multirow[c]{2}{*}{\rotatebox[origin=tr]{90}{Actual}}
      & Yes  & 100 & 0   \\[1.5ex]
      & No  & 10   & 80 \\ 
      \cline{2-4}
    \end{tabular}
    \caption{Bottom right caption}
  \end{minipage}
\end{table}

\end{document}

我喜欢booktabs视图稍微好一点:

在此处输入图片描述

\documentclass{article}

\usepackage{booktabs,eqparbox}

\begin{document}

\begin{table}
  \centering

  \begin{minipage}{.4\linewidth}
    \centering
    {\bfseries\strut Top left title}

    \begin{tabular}{ l c c }
      \toprule
      & \multicolumn{2}{c}{\bfseries Predicted} \\
      \cmidrule(lr){2-3}
      \bfseries Actual & \itshape Yes & \itshape No \\
      \midrule
      \itshape Yes & \eqmakebox[apval][r]{100} & \eqmakebox[apval][r]{  0} \\
      \itshape No  & \eqmakebox[apval][r]{ 10} & \eqmakebox[apval][r]{ 80} \\
      \bottomrule
    \end{tabular}

    \caption{Top left caption}
  \end{minipage}%
  \quad % ----------------------------------
  \begin{minipage}{.4\linewidth}
    \centering
    {\bfseries\strut Top right title}

    \begin{tabular}{ l c c }
      \toprule
      & \multicolumn{2}{c}{\bfseries Predicted} \\
      \cmidrule(lr){2-3}
      \bfseries Actual & \itshape Yes & \itshape No \\
      \midrule
      \itshape Yes & \eqmakebox[apval][r]{100} & \eqmakebox[apval][r]{  0} \\
      \itshape No  & \eqmakebox[apval][r]{ 10} & \eqmakebox[apval][r]{ 80} \\
      \bottomrule
    \end{tabular}
    \caption{Top right caption}
  \end{minipage}

  \bigskip

  \begin{minipage}{.4\linewidth}
    \centering
    {\bfseries\strut Bottom left title}

    \begin{tabular}{ l c c }
      \toprule
      & \multicolumn{2}{c}{\bfseries Predicted} \\
      \cmidrule(lr){2-3}
      \bfseries Actual & \itshape Yes & \itshape No \\
      \midrule
      \itshape Yes & \eqmakebox[apval][r]{100} & \eqmakebox[apval][r]{  0} \\
      \itshape No  & \eqmakebox[apval][r]{ 10} & \eqmakebox[apval][r]{ 80} \\
      \bottomrule
    \end{tabular}
    \caption{Bottom left caption}
  \end{minipage}%
  \quad % ----------------------------------
  \begin{minipage}{.4\linewidth}
    \centering
    {\bfseries\strut Bottom right title}

    \begin{tabular}{ l c c }
      \toprule
      & \multicolumn{2}{c}{\bfseries Predicted} \\
      \cmidrule(lr){2-3}
      \bfseries Actual & \itshape Yes & \itshape No \\
      \midrule
      \itshape Yes & \eqmakebox[apval][r]{100} & \eqmakebox[apval][r]{  0} \\
      \itshape No  & \eqmakebox[apval][r]{ 10} & \eqmakebox[apval][r]{ 80} \\
      \bottomrule
    \end{tabular}
    \caption{Bottom right caption}
  \end{minipage}
\end{table}

\end{document}

eqparbox's\eqmakebox只是一种针对c输入列的快速水平对齐技术。

相关内容