5

I used the proposed example in the "confusion matrix using only LaTeX code"

I increased the number of classes and until 9x9 confusion matrix, everything worked very well, but for 10 or higher numbers it got some errors. I upload the example with 10 columns:

\documentclass{article}
\usepackage{graphicx}

\newcommand\MyBox[1]{%
  \fbox{\parbox[c][.7cm][c]{.7cm}{\centering #1}}%
}
\newcommand\MyVBox[1]{%
  \parbox[c][.7cm][c]{1cm}{\centering\bfseries #1}%
}  
\newcommand\MyHBox[2][\dimexpr.7cm+2\fboxsep\relax]{%
  \parbox[c][1cm][c]{#1}{\centering\bfseries #2}%
}  
\newcommand\MyTBox[10]{%
  \MyVBox{#1}\MyBox{#2}\hspace*{-\fboxrule}\MyBox{#3}\hspace*{-\fboxrule}%
  \MyBox{#4}\hspace*{-\fboxrule}%
  \MyBox{#5}\hspace*{-\fboxrule}%
  \MyBox{#6}\hspace*{-\fboxrule}%
  \MyBox{#7}\hspace*{-\fboxrule}%
  \MyBox{#8}\hspace*{-\fboxrule}%
  \MyBox{#9}\hspace*{-\fboxrule}%
  \MyBox{#10}\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}
\MyHBox{D}\MyHBox{E}\MyHBox{F}\par

\MyTBox{A}{1}{2}{3}{4}{5}{6}{7}{8}{9}
\MyTBox{B}{2}{3}{4}{5}{6}{7}{8}{9}{10}
\MyTBox{C}{3}{4}{5}{6}{7}{8}{9}{10}{11}
\MyTBox{D}{4}{5}{6}{7}{8}{9}{10}{11}{12}
\MyTBox{E}{5}{6}{7}{8}{9}{10}{11}{12}{13}
\MyTBox{F}{6}{7}{8}{9}{10}{11}{12}{13}{14}
}

\end{document}
2
6

Rather than using 10 arguments for your macro you're better off using a comma separated list and then processing it using something like docsvlist from the etoolbox package. With this small modification your code produces:

enter image description here

Here's the full code:

\documentclass{article}
\usepackage{graphicx}

\newcommand\MyBox[1]{%
  \fbox{\parbox[c][.7cm][c]{.7cm}{\centering #1}}%
}
\newcommand\MyVBox[1]{%
  \parbox[c][.7cm][c]{1cm}{\centering\bfseries #1}%
}
\newcommand\MyHBox[2][\dimexpr.7cm+2\fboxsep\relax]{%
  \parbox[c][1cm][c]{#1}{\centering\bfseries #2}%
}
\usepackage{etoolbox}
\newcommand\MyTBox[3]{%
  \MyVBox{#1}
  \renewcommand*\do[1]{\MyBox{##1}\hspace*{-\fboxrule}}
  \docsvlist{#2}
  \MyBox{#3}\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}
\MyHBox{D}\MyHBox{E}\MyHBox{F}\par

\MyTBox{A}{1, 2, 3, 4, 5, 6, 7, 8}{9}
\MyTBox{B}{2, 3, 4, 5, 6, 7, 8, 9}{10}
\MyTBox{C}{3, 4, 5, 6, 7, 8, 9, 10}{11}
\MyTBox{D}{4, 5, 6, 7, 8, 9, 10, 11}{12}
\MyTBox{E}{5, 6, 7, 8, 9, 10, 11, 12}{13}
\MyTBox{F}{6, 7, 8, 9, 10, 11, 12, 13}{14}
}

\end{document}

I made \MyTBox have three arguments as there is "special" processing for the header, body and footer respectively. This said, I'd probably do this differently using something like tikz, although this really depends on what you are really putting inside these macros:) -- but I like your macros too!

0
0

Thanks, I followed the comment from @daleif and managed to do it.

\newcommand\MyTBox[9]{%
 %....
 \MyTBoxcontinued
 }  
\newcommand\MyTBoxcontinued[2]{%
 %two more arguments
 }

In the following, I uploaded the code and the resulted image.

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage{tipa}
\usepackage[normalem]{ulem}
\newcommand\MyBox[1]{%
  \fbox{\parbox[c][.7cm][c]{.7cm}{\centering #1}}%
}
\newcommand\MyVBox[1]{%
  \parbox[c][.7cm][c]{1cm}{\centering\bfseries #1}%
}  
\newcommand\MyHBox[2][\dimexpr.7cm+2\fboxsep\relax]{%
  \parbox[c][1cm][c]{#1}{\centering\bfseries #2}%
}  
\newcommand\MyTBox[9]{%
  \MyVBox{#1}\MyBox{#2}\hspace*{-\fboxrule}\MyBox{#3}\hspace*{-\fboxrule}%
  \MyBox{#4}\hspace*{-\fboxrule}%
  \MyBox{#5}\hspace*{-\fboxrule}%
  \MyBox{#6}\hspace*{-\fboxrule}%
  \MyBox{#7}\hspace*{-\fboxrule}%
  \MyBox{#8}\hspace*{-\fboxrule}%
  \MyBox{#9}\hspace*{-\fboxrule}%
  \MyTBoxcontinued
}  
\newcommand\MyTBoxcontinued[2]{%
 \MyBox{#1}\hspace*{-\fboxrule}%    
 \MyBox{#2}\par\vspace{-\fboxrule}
}

\begin{document}

{
\offinterlineskip
\hspace*{1cm}\MyHBox{/\textipa{a}/}\MyHBox{/\textipa{E}/}\MyHBox{\textipa{/I/}}
\MyHBox{/\reflectbox{\textipa{c}}/}\MyHBox{/\textipa{U}/}\MyHBox{/\textipa{a:}/}
\MyHBox{/\textipa{e}/}\MyHBox{/\textipa{i}/}\MyHBox{/\textipa{o}/}\MyHBox{/\textipa{u}/}\par

\MyTBox{/\textipa{a}/}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}
\MyTBox{/\textipa{E}/}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}
\MyTBox{/\textipa{I}/}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}
\MyTBox{/\reflectbox{\textipa{c}}/}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}
\MyTBox{/\textipa{U}/}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}
\MyTBox{/\textipa{a:}/}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}
\MyTBox{/\textipa{e}/}{7}{8}{9}{10}{11}{12}{13}{14}{15}{16}
\MyTBox{/\textipa{o}/}{8}{9}{10}{11}{12}{13}{14}{15}{16}{17}
\MyTBox{/\textipa{u}/}{9}{10}{11}{12}{13}{14}{15}{16}{17}{18}
}

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