2

I used proposed code in How to construct a confusion matrix in LaTeX? to create a confusion matrix:

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

enter image description here

This is a little big for my two columns article. How can I decease (scale) size of it?

Ps.

I'm using \documentclass[conference,hidelinks]{IEEEtran} as document class.

  • 1
    Your MWE doesn't feature a two-column layout, so it's a bit hard to judge the seriousness of the problem. If I add the option twocolumn to the \documentclass instruction of your example code, the matrix fits perfectly well in the available space. Upshot: please indicate in more detail how you set up two-column mode for your document. – Mico Apr 08 '15 at 13:31
  • Thank you for your commnet. \documentclass[conference,hidelinks]{IEEEtran} is documentclass that I'm using. – user2991243 Apr 08 '15 at 13:33
  • 1
    The confusion matrix produced by the example code would appear to fit easily in the width of the columns set up by the IEEEtran document class. Please consider posting a screenshot to illustrate more clearly what the problem is. – Mico Apr 08 '15 at 13:38
  • Compare to table it is so big in above added screenshot. – user2991243 Apr 08 '15 at 13:43
  • I'm confused. So, the issue is not, then, that the matrix won't fit in the available column space? Instead, you just want to make it smaller so as to make it look more proportionate with some other table in the document? – Mico Apr 08 '15 at 13:51
  • Yes Mico. That's true. I think this size isn't appropriate in my article. – user2991243 Apr 08 '15 at 13:52
  • 1
    Since you're loading the graphicx package, you could use that package's \scalebox macro to scale down the confusion matrix. Start with \scalebox{0.8}{<code for confusion matrix>}. – Mico Apr 08 '15 at 13:54
  • Please add your answer (edit above code with proposed \scalebox. + adding caption and label to it. thanks. – user2991243 Apr 08 '15 at 14:05
  • 1
    I've posted an answer that illustrates the use of \scalebox. I'm afraid I'm a dreadful psychic; I thus won't venture a guess as to what the appropriate arguments for \caption and \label may be. I trust you can figure out on your own how to provide these instructions. – Mico Apr 08 '15 at 14:16

1 Answers1

2

If the confusion matrix, as produced by the code given in the earlier answer, is too large for your taste (even though it fits easily inside the available space), you could either edit the code to reduce the various dimensions by, say, 20 percent, or you could place the code inside a \scalebox{0.8}{<code for confusion matrix>} directive.

The code below uses the second approach. It shows both an unscaled confusion matrix and one that's scaled down 20 percent.

enter image description here

\documentclass[conference,hidelinks]{IEEEtran}
\usepackage{array,graphicx,multirow}
\usepackage{lipsum} % for filler text

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

Two sizes: First unscaled, then scaled down 20\%

\begin{center}
\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{11}{*}{\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} 

\bigskip
\scalebox{0.8}{% 
\begin{tabular}{c >{\bfseries}r @{\hspace{0.7em}}c @{\hspace{0.4em}}c @{\hspace{0.7em}}l}
  \multirow{11}{*}{\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{center}

\lipsum[2] % filler text

\end{document}
Mico
  • 506,678