![混淆矩阵的颜色背景](https://linux22.com/image/397478/%E6%B7%B7%E6%B7%86%E7%9F%A9%E9%98%B5%E7%9A%84%E9%A2%9C%E8%89%B2%E8%83%8C%E6%99%AF.png)
所以我找到了这个奇妙的混淆矩阵这线程。我想知道如何为不同框的背景添加颜色。
\documentclass{article}
\usepackage{array}
\usepackage{graphicx}
\usepackage{multirow}
\newcommand\MyBox[2]{
\fbox{\lower0.75cm
\vbox to 1.7cm{\vfil
\hbox to 1.7cm{\hfil\parbox{1.4cm}{#1\\#2}\hfil}
\vfil}%
}%
}
\begin{document}
\noindent
\renewcommand\arraystretch{1.5}
\setlength\tabcolsep{0pt}
\begin{tabular}{c >{\bfseries}r @{\hspace{0.7em}}c @{\hspace{0.4em}}c
@{\hspace{0.7em}}l}
\multirow{10}{*}{\rotatebox{90}{\parbox{1.1cm}{\bfseries\centering actual\\
value}}} &
& \multicolumn{2}{c}{\bfseries Prediction outcome} & \\
& & \bfseries p & \bfseries n & \bfseries total \\
& p$'$ & \MyBox{True}{Positive} & \MyBox{False}{Negative} & P$'$ \\[2.4em]
& n$'$ & \MyBox{False}{Positive} & \MyBox{True}{Negative} & N$'$ \\
& total & P & N &
\end{tabular}
\end{document}
答案1
例如,你可以用包中添加颜色的宏fbox
来替换。新命令现在定义为:fcolorbox
xcolor
MyBox
\MyBox{<frame color>}{<background color>}{<text1>}{<text2>}
输出:
代码:
\documentclass{article}
\usepackage{array}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{xcolor}
\newcommand\MyBox[4]{
\fcolorbox{#1}{#2}{\lower0.75cm
\vbox to 1.7cm{\vfil
\hbox to 1.7cm{\hfil\parbox{1.4cm}{#3\\#4}\hfil}
\vfil}%
}%
}
\begin{document}
\noindent
\renewcommand\arraystretch{1.5}
\setlength\tabcolsep{0pt}
\begin{tabular}{c >{\bfseries}r @{\hspace{0.7em}}c @{\hspace{0.4em}}c
@{\hspace{0.7em}}l}
\multirow{10}{*}{\rotatebox{90}{\parbox{1.1cm}{\bfseries\centering actual\\
value}}} &
& \multicolumn{2}{c}{\bfseries Prediction outcome} & \\
& & \bfseries p & \bfseries n & \bfseries total \\
& p$'$ & \MyBox{red}{yellow}{True}{Positive} & \MyBox{orange}{white}{False}{Negative} & P$'$ \\[2.4em]
& n$'$ & \MyBox{green}{blue}{False}{Positive} & \MyBox{black}{red}{True}{Negative} & N$'$ \\
& total & P & N &
\end{tabular}
\end{document}