# confusion matrix with [ ] delimeters

I would like to make a confusion matrix that looks like the one on the picture. How can I achive this? Thanks

• Jul 13, 2015 at 15:12

% arara: pdflatex

\documentclass{article}
\usepackage{blkarray}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{mathtools}

\begin{document}
$\renewcommand{\arraystretch}{1.6} \begin{blockarray}{c@{}ccc} &&\BAmulticolumn{2}{c}{\text{observed}}\\[-2\jot] && 0 & 1 \\ \begin{block}{c@{\hspace{.6em}}c[cc]} \multirow{2}{*}{\rotatebox[origin=c]{90}{predicted}} & 0 & a=1 & b=2\\ & 1 & c=3 & d=4 \\ \end{block} \end{blockarray}$
\end{document}


• @OlgaLyashevska Glad to hear that. Jul 13, 2015 at 14:11

With {NiceMatrix} of the eponymous package.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\renewcommand{\arraystretch}{1.2}
$\begin{NiceMatrix} & & \Block{1-2}{\text{observed}} \\ & & 0 & 1 \\ \Block{2-1}{\rotate \text{predicted}} & 0 & a=1 & b=2 \\[1mm] & 1 & c=2 & d=4 \CodeAfter \SubMatrix[{3-3}{4-4}] \end{NiceMatrix}$

\end{document}