混淆矩阵的颜色背景

混淆矩阵的颜色背景

所以我找到了这个奇妙的混淆矩阵线程。我想知道如何为不同框的背景添加颜色。

\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来替换。新命令现在定义为:fcolorboxxcolorMyBox

 \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}

相关内容