我制作了下表:
\documentclass{article}
\usepackage{multirow}
\usepackage{multicol}
\begin{document}
\def\arraystretch{1.5}
\begin{tabular}{|c|c|ccc|} \hline
& & \multicolumn{3}{c|}{Actual} \\ \hline
& Class & Low & Med. & High \\ \hline
\multirow{3}{*}{Prediction} & Low & $0$ & $0$ & $0$ \\
& Med. & $10$ & $98$ & $1$ \\
& High & $0$ & $0$ & $0$ \\ \hline
\end{tabular}
\end{document}
结果如下:
我只是好奇是否有任何方法可以去除里面没有任何内容的盒子周围的线条?
答案1
这里没有必要multicol
。
\documentclass{article}
\usepackage{multirow}
\begin{document}
\def\arraystretch{1.5}
\begin{tabular}{|c|c|ccc|}
\cline{3-5}
\multicolumn{1}{c}{} & & \multicolumn{3}{c|}{Actual} \\ \cline{2-5}
\multicolumn{1}{c|}{} & Class & Low & Med. & High \\ \hline
\multirow{3}{*}{Prediction} & Low & $0$ & $0$ & $0$ \\
& Med. & $10$ & $98$ & $1$ \\
& High & $0$ & $0$ & $0$ \\ \hline
\end{tabular}
\end{document}
答案2
我建议省略所有行,这样看起来更好。在下面的 mwe 中,我展示了两个版本。请查看我的漂亮打印,以便能够更快地看到表格的结构...
MWE [重要的代码变化标有<======
]:
\documentclass{article}
\usepackage{multirow}
\usepackage{multicol}
\begin{document}
\def\arraystretch{1.5}
How about without lines:
\begin{tabular}{c c ccc} %\hline
& & \multicolumn{3}{c}{Actual} \\ %\hline
& Class & Low & Med. & High \\ %\hline
\multirow{3}{*}{Prediction} & Low & $0$ & $0$ & $0$ \\
& Med. & $10$ & $98$ & $1$ \\
& High & $0$ & $0$ & $0$ \\ %\hline
\end{tabular}
Version with lines:
\begin{tabular}{|c|c|ccc|} \cline{3-5} % <==============================
\multicolumn{2}{c}{} & \multicolumn{3}{|c|}{Actual} \\ \cline{2-5} % <===========
\multicolumn{1}{c|}{} & Class & Low & Med. & High \\ \hline % <========
\multirow{3}{*}{Prediction} & Low & $0$ & $0$ & $0$ \\ % <=======
& Med. & $10$ & $98$ & $1$ \\
& High & $0$ & $0$ & $0$ \\ \hline
\end{tabular}
\end{document}
及其结果: