# vertical text orientation (multiple rows) in tabular environment

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?

-
have a look at rotate+table+labels‌​, it seems like there are quite a few questions that have dealt with similar issues – cmhughes Apr 18 '12 at 11:32

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.

\documentclass{article}
\usepackage{graphicx}
\makeatletter
\newsavebox\zzz
\def\mystrut{%
\dimen@\wd\zzz
\divide\dimen@\thr@@
\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}

-
Thanks, this works. Is there a way to measure the width of the rotated box and give each of the last 3 rows 1/3 of that as height? And then to vertically center the text in those rows? – D.Roepo Apr 20 '12 at 15:12
see updated answer – David Carlisle Apr 20 '12 at 15:31
Nice, applied that to all tables! Imagine 'Category B' is 'Category LongName'. Is it possible to get something like \savebox\zzz{Category\\LongName}? Also is the vertical text closer to the bottom of the last than to the top of the first row. Can that be centred? – D.Roepo Apr 20 '12 at 16:03
as always with savebox if you want multiple lines you need to put it in a parbox (or better here a tabular as then you can still measure so \savebox\zzz{\begin{tabular}{l}Category\\ LongName\end{tabular}} you can use \rlap{\hspace{10pt}\usebox\zzz} to raise it a bit, you need to choose the value by eye.... centering row spans automatically is tricky unless you re-implement almost all of latex table internals – David Carlisle Apr 20 '12 at 16:13
The arithmetic in that mystrut is nonsense I will update in a bit (I am adding not subtracting for a start: you should do what I meant not what I wrote:-) – David Carlisle Apr 20 '12 at 16:15