我一直在嘗試使用 pdfLatex 建立 3x3 混淆矩陣。到目前為止,我的輸出以及我的程式碼都包含在下圖中。
我在矩陣的兩個方面遇到了麻煩。
首先,我需要增加「實際值」與矩陣兩側的「左」、「右」和「直」行標題之間的間距,但到目前為止我還無法做到正確。
其次,我需要將第二個矩陣底部的子標題“(b) Part 2”向左移動,以便它與矩陣的中間行對齊,就像子標題“(a) Part 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}