我一直在尝试使用 pdfLatex 构建 3x3 混淆矩阵。到目前为止,我的输出以及代码都包含在下图中。
我对矩阵的两个方面感到困惑。
首先,我需要增加“实际值”与矩阵边缘的“左”、“右”和“直”行标题之间的空间,但到目前为止我还无法做到正确。
其次,我需要将第二个矩阵底部的子标题“(b)第 2 部分”向左移动,使其与矩阵的中间行对齐,就像子标题“(a)第 1 部分”对第一个矩阵的作用一样。
我该如何进行上述两个修复?
我已尝试尽可能地整理代码。我是个新手,因此可能没有使用最佳方法。如有任何关于改进的进一步建议,我将不胜感激。
谢谢。
\begin{table}[h!]
\begin{center}
\setlength\tabcolsep{0pt}
\caption{Confusion Matrix}
\label{tab:table1}
\begin{subtable}{0.49\linewidth}
\begin{tabular}{c|c|c|c|c}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{3}{c}{\bfseries Prediction outcome} \\
\multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{\textbf{Left}} & \multicolumn{1}{c}{\textbf{Straight}} & \multicolumn{1}{c}{\textbf{Right}}\\
\multicolumn{1}{c}{\multirow{13}{*}{\rotatebox{90}{\parbox{1.1cm}{\bfseries \mbox{Actual Value}}}}} & \multicolumn{1}{c}{\multirow{-2}{*}{\rotatebox{90}{\parbox{1.1cm}{\textbf{Left}}}}} & \multicolumn{1}{c}{\MyBox{0}{ }} & \multicolumn{1}{c}{\MyBox{1}{ }} & \multicolumn{1}{c}{\MyBox{2}{ }}\\
\multicolumn{1}{c}{} & \multicolumn{1}{c}{\multirow{1}{*}{\rotatebox{90}{\parbox{1cm}{\textbf{Straight}}}}} & \multicolumn{1}{c}{\MyBox{0}{ }} & \multicolumn{1}{c}{\MyBox{1}{ }} & \multicolumn{1}{c}{\MyBox{2}{ }}\\
\multicolumn{1}{c}{} & \multicolumn{1}{c}{\multirow{-2}{*}{\rotatebox{90}{\parbox{1.1cm}{\textbf{Right}}}}} & \multicolumn{1}{c}{\MyBox{0}{ }} & \multicolumn{1}{c}{\MyBox{1}{ }} & \multicolumn{1}{c}{\MyBox{2}{ }}
\end{tabular}
\caption{Part 1}
\end{subtable}
\begin{subtable}{0.49\linewidth}
\begin{tabular}{c|c|c|c|c}
\multicolumn{3}{c}{\bfseries Prediction outcome} & \multicolumn{1}{c}{} \\
\multicolumn{1}{c}{\textbf{Left}} & \multicolumn{1}{c}{\textbf{Straight}} & \multicolumn{1}{c}{\textbf{Right}} & \multicolumn{1}{c}{}\\
\multicolumn{1}{c}{\MyBox{1000}{ }} & \multicolumn{1}{c}{\MyBox{1}{ }} & \multicolumn{1}{c}{\MyBox{2}{ }} & \multicolumn{1}{c}{\multirow{3}{*}{\rotatebox{270}{\parbox{1cm}{\textbf{Left}}}}} & \multicolumn{1}{c}{\multirow{9}{*}{\rotatebox{270}{\parbox{1.2cm}{\bfseries \mbox{Actual Value}}}}}\\
\multicolumn{1}{c}{\MyBox{0}{ }} & \multicolumn{1}{c}{\MyBox{1}{ }} & \multicolumn{1}{c}{\MyBox{2}{ }} & \multicolumn{1}{c}{\multirow{-2}{*}{\rotatebox{270}{\parbox{-10cm}{\textbf{Straight}}}}} & \multicolumn{1}{c}{}\\
\multicolumn{1}{c}{\MyBox{0}{ }} & \multicolumn{1}{c}{\MyBox{1}{ }} & \multicolumn{1}{c}{\MyBox{2}{ }} & \multicolumn{1}{c}{\multirow{1}{*}{\rotatebox{270}{\parbox{1.1cm}{\textbf{Right}}}}} & \multicolumn{1}{c}{}
\end{tabular}
\caption{Part 2}
\end{subtable}
\end{center}
\end{table}
答案1
以下是其中一个子表的更简单代码。希望它能满足您的要求:
\documentclass{article}
\usepackage{subcaption}
\usepackage{rotating, multirow}
\usepackage{graphicx}
\newcommand{\MyBox}[1]{{\parbox[c][1.4cm][c]{1.1cm}{#1}}}
\newcommand{\rotbox}[1]{ \rotatebox[origin = c]{90}{\makebox[0pt]{\bfseries#1}}}
\begin{document}
\begin{table}[h!]
\centering
\caption{Confusion Matrix}
\label{tab:table1}
\begin{subtable}{0.49\linewidth}
\begin{tabular}{c@{\enspace }c|c|c|c|}
\multicolumn{2}{c}{} & \multicolumn{3}{c}{\bfseries Prediction outcome} \\
\multicolumn{2}{c}{} & \multicolumn{1}{c}{\textbf{Left}} & \multicolumn{1}{c}{\makebox[0pt]{\textbf{Straight}}} & \multicolumn{1}{c}{\textbf{Right}}\\[0.5ex]
\cline{3-5}
& \rotbox{Left} & \MyBox{0} & \MyBox{1} & \MyBox{2} \\
\cline{3-5}
\rotbox{Actual value} & \rotbox{Straight} & \MyBox{0} & \MyBox{1} & \MyBox{2} \\
\cline{3-5}
& \rotbox{Right} & \MyBox{0} & \MyBox{1} & \MyBox{2} \\
\cline{3-5}
\end{tabular}
\caption{Part 1}
\end{subtable}
\end{table}
\end{document}