[Tex/LaTex] How to add a Vertical Multi-row Title to a Table

tables

I have created a table, shown in black below. I would like to add a vertical title to the left side of my table (as shown in in green, should be black). How can I achieve this?

enter image description here
Here is the LaTeX (MWE) for what I have so far:

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

\begin{table}[]
    \centering
    \begin{tabular}{c||c|c|c|c|c|c|c|c|c|c|}
    &\multicolumn{10}{|c|}{Correct Label}\\
    &0    &1    &2    &3    &4    &5    &6    &7    &8    &9   \\ \hline \hline
    0 &974  &0    &2    &0    &1    &2    &6    &0    &4    &2   \\ \hline
    1 &0    &1124 &0    &1    &1    &0    &2    &4    &0    &4   \\ \hline
    2 &0    &2    &1012 &3    &1    &0    &0    &9    &2    &1   \\ \hline
    3 &0    &3    &3    &989  &0    &10   &1    &2    &0    &2   \\ \hline
    4 &0    &0    &2    &0    &960  &0    &1    &0    &3    &6   \\ \hline
    5 &0    &1    &0    &3    &0    &870  &3    &0    &2    &5   \\ \hline
    6 &1    &1    &1    &0    &4    &4    &942  &0    &2    &1   \\ \hline
    7 &1    &0    &7    &3    &1    &1    &0    &1005 &2    &6   \\ \hline
    8 &3    &4    &5    &6    &2    &5    &2    &4    &956  &3   \\ \hline
    9 &1    &0    &0    &5    &12   &0    &1    &4    &3    &979 
    \end{tabular}
    \caption{Correct label vs NN label}
    \label{tab:my_label}
\end{table}

\end{document}

Thanks,
Oli

Best Answer

This can be done by an additional column (having 12 columns in total now) at the left margin of the table and using \multirow{10}{*}{\rotatebox{90}{NN Label}} in the third row. \rotatebox is a macro from graphicx package.

I've changed the 10 occurences of |c| to *{10}{c|} to simplify the code.

In order to prevent horizontal lines for the full table, use \cline{2-12}, i.e. from the 2nd to the 12th column then.

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{multirow}
\usepackage{graphicx}
\begin{document}

\begin{table}
    \centering
    \begin{tabular}{@{}cc||*{10}{c|}}
  \multicolumn{1}{c}{}  &   &\multicolumn{10}{|c|}{Correct Label}\\
    \multicolumn{1}{c}{} & &0    &1    &2    &3    &4    &5    &6    &7    &8    &9   \\ \hline \hline
    \multirow{10}*{\rotatebox{90}{NN Label}}  
   & 0 &974  &0    &2    &0    &1    &2    &6    &0    &4    &2   \\ \cline{2-12} 
   & 1 &0    &1124 &0    &1    &1    &0    &2    &4    &0    &4   \\ \cline{2-12}
   & 2 &0    &2    &1012 &3    &1    &0    &0    &9    &2    &1   \\ \cline{2-12}
   & 3 &0    &3    &3    &989  &0    &10   &1    &2    &0    &2   \\ \cline{2-12}
   & 4 &0    &0    &2    &0    &960  &0    &1    &0    &3    &6   \\ \cline{2-12}
   & 5 &0    &1    &0    &3    &0    &870  &3    &0    &2    &5   \\ \cline{2-12}
   & 6 &1    &1    &1    &0    &4    &4    &942  &0    &2    &1   \\ \cline{2-12}
   & 7 &1    &0    &7    &3    &1    &1    &0    &1005 &2    &6   \\ \cline{2-12}
   & 8 &3    &4    &5    &6    &2    &5    &2    &4    &956  &3   \\ \cline{2-12}
   & 9 &1    &0    &0    &5    &12   &0    &1    &4    &3    &979 
    \end{tabular}
    \caption{Correct label vs NN label}
    \label{tab:my_label}
\end{table}

\end{document}

enter image description here

Related Question