3

With respect to this link: confusion matrix using only LaTeX code, which was very helpful, I was able to reduce the example to a 2x2 matrix, however when trying to center the whole structure, the y-axis label is centered independent from the rest of the table structure.

enter image description here

This was done by encapsulating the table in a figure, and subsequently centering environment. My question is now, how can I center the table as whole?

I wish to be able to place the table in its entirety where I want and add both labels and captions as well if possible.

Edit: Added example code. Also included all packages used since I'm not sure whether these wel affect possible solutions.

%%%% Add Packages %%%%
\documentclass[11pt]{report}
\usepackage{graphicx}

%%%% Confusion Matrix Body %%%%
\newcommand\MyBox[1]{%
  \fbox{\parbox[c][1.7cm][c]{1.7cm}{\centering #1}}%
  % Size of boxes
}
\newcommand\MyVBox[1]{%
  \parbox[c][1cm][c]{1cm}{\centering\bfseries #1}%
}  
\newcommand\MyHBox[2][\dimexpr1.7cm+2\fboxsep\relax]{%
  \parbox[c][1cm][c]{#1}{\centering\bfseries #2}%
}  
\newcommand\MyTBox[4]{%
  \MyVBox{#1}
  \MyBox{#2}\hspace*{-\fboxrule}%
  \MyBox{#3}\par\vspace{-\fboxrule}%
}  
%%%%

\begin{document}


\begin{figure}
\begin{center}
{

\offinterlineskip

\raisebox{-5cm}[0pt][0pt]{\rotatebox[origin=c]{90}{\parbox[c][0pt][c]{0cm}{\textbf{Actual}\\[20pt]}}}\par

\hspace*{1cm}\MyHBox[\dimexpr3.4cm+6\fboxsep\relax]{Predicted}\par

\hspace*{1cm}\MyHBox{30}\MyHBox{90}\par

\MyTBox{30}{9418}{1471}

\MyTBox{90}{144}{317}

}
\end{center}
\end{figure}
\end{document}
3
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. The cause of your problem will likely be explained by the code which generates the problem, please provide an MWE so we can see how you reach the faulty output.
    – Dai Bowen
    Jan 23, 2017 at 13:46
  • Fair enough! I've edited the question once more. Sorry for the inconvenience.
    – Andrew
    Jan 23, 2017 at 15:53
  • Please don't use \begin{center}...\end{center} inside figure or another floating environment.
    – user31729
    Jan 23, 2017 at 16:51

1 Answer 1

2

I have edit your source add a macro \newcommand*\rot{\rotatebox{90} and \parbox[c][0pt][c]{0cm}{\hspace{-3.5cm}\rot{\textbf{Actual}}\\[20pt]}}\par. I hope to have resolve your question.

enter image description here

\documentclass[11pt]{report}
\usepackage{graphicx}

%%%% Confusion Matrix Body %%%%
\newcommand\MyBox[1]{%
  \fbox{\parbox[c][1.7cm][c]{1.7cm}{\centering #1}}%
  % Size of boxes
}
\newcommand\MyVBox[1]{%
  \parbox[c][1cm][c]{1cm}{\centering\bfseries #1}%
}  
\newcommand\MyHBox[2][\dimexpr1.7cm+2\fboxsep\relax]{%
  \parbox[c][1cm][c]{#1}{\centering\bfseries #2}%
}  
\newcommand\MyTBox[4]{%
  \MyVBox{#1}
  \MyBox{#2}\hspace*{-\fboxrule}%
  \MyBox{#3}\par\vspace{-\fboxrule}%
}  
%%%%
\newcommand*\rot{\rotatebox{90}}

\begin{document}


\begin{figure}
\begin{center}
{

\offinterlineskip

\raisebox{-5cm}[0pt][0pt]{
\parbox[c][0pt][c]{0cm}{\hspace{-3.5cm}\rot{\textbf{Actual}}\\[20pt]}}\par

\hspace*{1cm}\MyHBox[\dimexpr3.4cm+6\fboxsep\relax]{Predicted}\par

\hspace*{1cm}\MyHBox{30}\MyHBox{90}\par

\MyTBox{30}{9418}{1471}

\MyTBox{90}{144}{317}

}
\end{center}
\end{figure}
\end{document}
1
  • 1
    I'm not sure if I should open another thread for this but I was wondering if it is also possible to place two of these horizontally next to each other without messing the figure up. I tried to use the subfig package and included the two figures both in a subfloat{} environment. This did not work unfortunately.
    – Andrew
    Jan 25, 2017 at 15:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .