[Tex/LaTex] vertical text orientation (multiple rows) in tabular environment

tables

I would like to create a table that is labelled like the axis of a plot, i.e. a vertical orientation of the y-axis' label. This is what I have

\begin{tabular}{rc|c|c|c|}
&&\multicolumn{3}{|c|}{Category A}\\
&&little&some&a lot\\
&little&&&\\
Category B&some&&\\
&a lot&&&\\\hline
\end{tabular}

But I would like the text 'Category B', to be vertical spanning from row 3-5 instead of being horizontal in row 4.

How do I achieve that?

Best Answer

enter image description here

Depending on exactly what you need, you may wish to adjust the spacing, but something like this:

Here I have added extra \hline to the table to make the spacing clearer, also the heading is backspaced by the depth of a table row so that it exactly fits (The first version got this wrong) this spacing may be adjusted in individual cases to gain better visual spacing if that is needed.

enter image description here

\documentclass{article}
\usepackage{graphicx}
\makeatletter
\newsavebox\zzz
\def\mystrut{%
\dimen@\wd\zzz
\divide\dimen@\thr@@
\advance\dimen@-\dp\@arstrutbox
\rule\z@\dimen@}

\def\rotatezzz{%
\rotatebox{90}{\rlap{\kern-\dp\@arstrutbox\usebox\zzz}}}

\makeatother
\begin{document}




\savebox\zzz{Category B}
\begin{tabular}{rc|c|c|c|}
&&\multicolumn{3}{|c|}{Category A}\\
&&little&some&a lot\\\hline
\mystrut&little&&&\\
\mystrut&some&&&\\
\mystrut\rotatezzz&a lot&&&\\\hline
\end{tabular}


\end{document}
Related Question