0

I am using Qrrbrbirlbel's solution to build the confusion matrix as given in the figure. The problem is when extend the rows and column to 10 as given in the code it gives me the error as stated in the title. I have to draw 14*14 matrix. Kindly help

      \documentclass{article}
\usepackage[table]{xcolor}
\usepackage{array,hhline}
\makeatletter
\newcommand*{\ccol}[1]{%
    \ifdim#1pt<.5pt\relax\else\color{white}\fi
    \edef\x{\noexpand\cellcolor[gray]{\strip@pt\dimexpr1pt-#1pt}}\x
    #1%
}
\newlength{\cellwidth}
\settowidth{\cellwidth}{0.00}
\def\jline{\\\hhline{~*{10}{|-}|}}
\makeatother

\begin{document}
    \begin{tabular}{l*{10}{|>{\centering\arraybackslash}m{\cellwidth}}|}
        \noalign{\gdef\w#1{\multicolumn{1}{c}{#1}}}
        \w{} & \w{hw} & \w{bx} & \w{wk} & \w{jg} & \w{cl} & \w{rn}\& \w{cl} & \w{rn}\& \w{cl} & \w{rn}\jline
        ving & \ccol{1} & 0 & 0 & 0 & 0 & 0& 0 & 0& 0 & 0\jline
        xing & 0 & \ccol{0.92} & \ccol{0.08} & 0 & 0 & 0 & 0 & 0& 0 & 0\jline
        king & 0 & \ccol{0.03} & \ccol{0.97} & 0 & 0 & 0& 0 & 0& 0 & 0\jline
        ging & 0 & 0 & 0 & \ccol{1} & 0 & 0& 0 & 0& 0 & 0\jline
        ping & 0 & 0 & 0 & 0 & \ccol{1} & 0& 0 & 0& 0 & 0\jline
        ning & 0 & 0 & 0 & 0 & 0 & \ccol{1}& 0 & 0& 0 & 0\jline
        ning & 0 & 0 & 0 & 0 & 0 & \ccol{1}& 0 & 0& 0 & 0\jline
        ning & 0 & 0 & 0 & 0 & 0 & \ccol{1}& 0 & 0& 0 & 0\jline
        ning & 0 & 0 & 0 & 0 & 0 & \ccol{1}& 0 & 0& 0 & 0\jline
        ning & 0 & 0 & 0 & 0 & 0 & \ccol{1}& 0 & 0& 0 & 0\jline
        \noalign{\global\let\w\undefined}
    \end{tabular}
\end{document}

enter image description here

umar
  • 115

1 Answers1

2

The problem appears to be comint from the definition of \w (possibly related).

The simplest fix would be to remove that definition and just manually write out the \multicolumn command for the first row:

    \begin{tabular}{l*{10}{|>{\centering\arraybackslash}m{\cellwidth}}|}
        % \noalign{\gdef\w#1{\multicolumn{1}{c}{#1}}}
        \multicolumn{1}{c}{}& \multicolumn{1}{c}{hw} & \multicolumn{1}{c}{bx} & \multicolumn{1}{c}{wk} & \multicolumn{1}{c}{jg} & \multicolumn{1}{c}{cl} & \multicolumn{1}{c}{rn} & \multicolumn{1}{c}{cl} & \multicolumn{1}{c}{rn} & \multicolumn{1}{c}{cl} & \multicolumn{1}{c}{rn}\jline
        ving & \ccol{1} & 0 & 0 & 0 & 0 & 0& 0 & 0& 0 & 0\jline
        xing & 0 & \ccol{0.92} & \ccol{0.08} & 0 & 0 & 0 & 0 & 0& 0 & 0\jline
        king & 0 & \ccol{0.03} & \ccol{0.97} & 0 & 0 & 0& 0 & 0& 0 & 0\jline
        ging & 0 & 0 & 0 & \ccol{1} & 0 & 0& 0 & 0& 0 & 0\jline
        ping & 0 & 0 & 0 & 0 & \ccol{1} & 0& 0 & 0& 0 & 0\jline
        ning & 0 & 0 & 0 & 0 & 0 & \ccol{1}& 0 & 0& 0 & 0\jline
        ning & 0 & 0 & 0 & 0 & 0 & \ccol{1}& 0 & 0& 0 & 0\jline
        ning & 0 & 0 & 0 & 0 & 0 & \ccol{1}& 0 & 0& 0 & 0\jline
        ning & 0 & 0 & 0 & 0 & 0 & \ccol{1}& 0 & 0& 0 & 0\jline
        ning & 0 & 0 & 0 & 0 & 0 & \ccol{1}& 0 & 0& 0 & 0\jline
        % \noalign{\global\let\w\undefined}
    \end{tabular}

Output:

output

pip
  • 1,847
  • Thank you very much. There is only one problem left that this in textstudio editor there are error appearing on & (highlighted with red color) and when i bring the mouse cursor over it gives(more cols then specified). Should i add the snapshot of it ? – umar Feb 23 '19 at 09:09
  • Does the message go if you change l*{10} to l*{11}? – pip Feb 23 '19 at 09:10
  • It remains the same even by replacing with 1*{11}. – umar Feb 23 '19 at 09:43
  • It is difficult for me to tell because I don't have texstudio. Perhaps the program does not recognise the \jline command. Does it still compile? If so, I wouldn't worry about it. – pip Feb 23 '19 at 09:56
  • Yes, It compile perfectly.. I was only worried about the warnings that are appearing on the & by highlighting with red color. – umar Feb 23 '19 at 10:02