-2

I am new to latex and in a pressing need to quickly design a fine confusion matrix (with text rotation) as in the attached screenshot:

enter image description here

I am not sure how the content can be customised in latex as in the shown table (Predicted column orientation, double-line horizontal line etc).

Any help would be appreciated.

EDIT

I would have love to use @Zarko's answer since I'm using `ieeetran` document class but I encountered an error:
The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}.

with some options defined in the command appearing in the output: enter image description here

super_ask
  • 125

2 Answers2

2

For double lines in tables you can use hhline package.

For rotation of text in tables \rotatebox. (explanation see here)

\documentclass{article}
\usepackage{hhline}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{adjustbox}
\newcommand\RotText[1]{\rotatebox{90}{\parbox{1.9 cm}{\raggedright#1}}}

\begin{document}

\begin{table}[h] \renewcommand{\arraystretch}{1.25} %\caption{Table} \label{tab:my-table} \centering \setlength\doublerulesep{0.8pt} % distance or the 2 lines in the double line \begin{tabular}{cccccccc} \specialrule{2pt}{1pt}{1pt} % thick line \multicolumn{8}{c}{\textbf{Actual}} \ \multicolumn{2}{c}{\textbf{}} & \textbf{Bike} & \textbf{Car} & \textbf{Walk} & \textbf{Run} & \textbf{Bus} & \textbf{Precision} \ \hline \multirow{5}{*}{\textbf{\RotText{Predicted}}} & \textbf{Bike} & 97.13 & 0.52 & 1.1 7& 0.40 & 0.58 & 97.33 \ & \textbf{Car} & 0.66 & 93.57 & 0.16 & 0.13 & 3.06 & 95.88 \ & \textbf{Walk} & 0.29 & 0.08 & 93.59 & 0.92 & 0.29 & 97.68 \ & \textbf{Run} & 0.37 & 0.05 & 0.93 & 92.82 & 0.20 & 98.36 \ & \textbf{Bus} & 0.92 & 2.42 & 0.40 & 0.32 & 93.11 & 95.81 \ \hline & \textbf{Recall} & 97.13 & 93.57 & 93.59 & 92.82 & 93.11 & \ \hhline{========} \end{tabular} \end{table}

\end{document}

enter image description here

Roland
  • 6,655
2

enter image description here

I suspect that you use ieeetran or similar document class. With employed siunitx package (for S columns), booktabs (for horizontal rules), multirow (for cell with vertical text), and \rotating and makecell (for rotate text in the first column) packages:

\documentclass{ieeetran}
\usepackage{rotating}
\usepackage{booktabs, makecell, multirow}
\NewExpandableDocumentCommand\mcc{O{1}m}
    {\multicolumn{#1}{c}{#2}}
\usepackage{siunitx}

\begin{document} \begin{table}[ht] \caption{Confusion matrix for SVM using pooled features} \label{tab:confusion} \settowidth\rotheadsize{\textbf{Predicted}} \centering \begin{tabular}{{2}{>{\bfseries}l} {6}{S[table-format=2.2]} } \toprule & & \mcc[6]{\textbf{Actual}} \ \cmidrule{3-8} & & {\textbf{Bike}} & {\textbf{Car}} & {\textbf{Walk}} & {\textbf{Run}} & {\textbf{Bus}} & {\textbf{Precision}}\ \midrule \multirow{5}{*}{\rothead{Predicted}} & Bike
& 97.13 & 0.52 & 1.17
& 0.40 & 0.58 & 97.88 \ & Car & 0.66 & 93.57 & 0.16 & 0.13 & 3.06 & 95.88 \ & Walk & & & & & & \ & Run & & & & & & \ & Bus & 0.92 & 2.42 & 0.40 & 0.32 & 93.11 & 95.81 \ \midrule & Recall & 97.13 & 93.57 & 93.82
& 92.82 & 93.11 & \ \bottomrule \end{tabular} \end{table} \end{document}

Zarko
  • 296,517
  • yes, actually I used ieee template. – super_ask Feb 22 '21 at 09:35
  • Got an Error: The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...} – super_ask Feb 22 '21 at 09:46
  • 1
    @super_ask, proposed MWE works out-of-box, if you have recent LaTeX installed. If not, It might help to add \usepackage{xparse} before \NewExpandableDocumentCommand in preamble of MWE. – Zarko Feb 22 '21 at 10:03
  • perfect, it works. – super_ask Feb 22 '21 at 10:26
  • @super_ask, of course it works. It also has aligned numbers at decimal points, superior professional look-out and simple, short code ;-). – Zarko Feb 22 '21 at 12:53