LaTeX 中的混淆矩陣

LaTeX 中的混淆矩陣

我在「僅使用 LaTeX 程式碼的混淆矩陣

我增加了類別的數量,直到 9x9 混淆矩陣,一切都運作良好,但對於 10 或更高的數字,它會出現一些錯誤。我上傳了包含 10 列的範例:

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

答案1

與其為巨集使用 10 個參數,不如使用逗號分隔的列表,然後使用類似套件docsvlist中的內容來處理它etoolbox。透過這個小修改,您的程式碼會產生:

在此輸入影像描述

這是完整的程式碼:

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

我提出\MyTBox了三個參數,因為分別對頁首、正文和頁尾進行了「特殊」處理。這就是說,我可能會使用類似的方法來做到這一點tikz,儘管這實際上取決於您在這些巨集中真正放入的內容:) - 但我也喜歡您的巨集!

答案2

謝謝,我按照@daleif的評論並設法做到了。

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

接下來,我上傳了程式碼和結果圖像。

在此輸入影像描述

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

相關內容