1

I need to make a table in this specific format

enter image description here

The main problem is that I do not want to use any other package and want to do it in only latex code!

Note: I found a related question but it uses TikZ to solve the problem. However I want pure latex code only.

  • 2
    May I ask why you want it to be pure (La)TeX? – Grimler Oct 6 '15 at 16:01
  • 1
    Confusion matrix is new to me. Do you mean correlation matrix? – user31729 Oct 6 '15 at 16:11
  • This is related, but uses packages: tex.stackexchange.com/questions/172578/…. My answer there uses xcolor, graphicx, and stackengine, but not tikz. – Steven B. Segletes Oct 6 '15 at 16:22
  • @ChristianHupfer Confusion matrix is used in binary machine learning classification problems / medical diagnosis and show frequencies of true positive, false positive, false negative and false positive cases and the subtotal tallies for a classifier or diagnosis method. – Mobius Pizza Oct 7 '15 at 10:19
3

Just graphicx to rotate the "Source2" label:

enter image description here

The code:

\documentclass{article}
\usepackage{graphicx}

\newcommand\MyBox[1]{%
  \fbox{\parbox[c][1.7cm][c]{1.7cm}{\centering #1}}%
}
\newcommand\MyVBox[1]{%
  \parbox[c][1.7cm][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}\hspace*{-\fboxrule}%
  \MyBox{#4}\par\vspace{-\fboxrule}
}  

\begin{document}

{
\offinterlineskip
\raisebox{-5cm}[0pt][0pt]{\rotatebox[origin=c]{90}{\parbox[c][0pt][c]{1cm}{\textbf{Source2}\\[20pt]}}}\par
\hspace*{1cm}\MyHBox[\dimexpr5.1cm+6\fboxsep\relax]{Source1}\par
\hspace*{1cm}\MyHBox{A}\MyHBox{B}\MyHBox{C}\par
\MyTBox{A}{0.1}{0.3}{0.5}
\MyTBox{B}{0.5}{0.2}{0.1}
\MyTBox{C}{0.4}{0.7}{0.2}
}

\end{document}
2

I won't claim this is a very good solution, but the built-in picture can be used for this. I did use graphicx for \rotatebox though.

enter image description here

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\setlength\unitlength{1cm}
\begin{picture}(4,4)
\multiput(0.1,0.1)(0,1){4}{\line(1,0){3}}
\multiput(0.1,0.1)(1,0){4}{\line(0,1){3}}
\put(0.5,0.5){1}
\put(1.5,0.5){2}
\put(2.5,0.5){3}

\put(0.5,1.5){4}
\put(1.5,1.5){5}
\put(2.5,1.5){6}

\put(0.5,2.5){7}
\put(1.5,2.5){8}
\put(2.5,2.5){9}

\put(-0.5,2.5){A}
\put(-0.5,1.5){B}
\put(-0.5,0.5){C}

\put(0.5,3.5){A}
\put(1.5,3.5){B}
\put(2.5,3.5){C}

\put (-1.2,1.5){\rotatebox{90}{Text}}
\put(1.2,4.2){Text}
\end{picture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.