[Tex/LaTex] How to rotate text in a cell and center it vertically and horizontally

rotatingtables

I am creating a table and, after using \multirow, I want to rotate the text of this column and have it centered vertically and horizontally inside its cell. The code I am using would be similar to this one:

\begin{tabular}{ |c|c|c| }
\hline
\multirow{8}{*}{Text} & row 1 & row 1 \\
 & row 2 & row 2 \\
 & row 3 & row 3 \\
 & row 4 & row 4 \\
 & row 5 & row 5 \\
 & row 6 & row 6 \\
 & row 7 & row 7 \\
 & row 8 & row 8 \\ \hline
\end{tabular} 

Thanks.

Best Answer

You can do this with or without multirow. Use graphicx for the rotation via \rotatebox[<opts>]{<deg>}{<stuff>}:

enter image description here

\documentclass{article}
\usepackage{graphicx,multirow}
\begin{document}
\begin{tabular}{ |c|c|c| }
  \hline
  \multirow{8}{*}{\rotatebox[origin=c]{90}{Text}} & row 1 & row 1 \\
   & row 2 & row 2 \\
   & row 3 & row 3 \\
   & row 4 & row 4 \\
   & row 5 & row 5 \\
   & row 6 & row 6 \\
   & row 7 & row 7 \\
   & row 8 & row 8 \\
  \hline
\end{tabular}

\begin{tabular}{ |c|c|c| }
  \hline
   & row 1 & row 1 \\
   & row 2 & row 2 \\
   & row 3 & row 3 \\
  \raisebox{-.5\normalbaselineskip}[0pt][0pt]{\rotatebox[origin=c]{90}{Text}} & row 4 & row 4 \\
   & row 5 & row 5 \\
   & row 6 & row 6 \\
   & row 7 & row 7 \\
   & row 8 & row 8 \\
  \hline
\end{tabular}
\end{document}

With multirow you don't need to worry about the placement, while without you need to place the text in the appropriate location, and perhaps lower/raise it into position. Also, you have to flatten the content (done by using the [0pt][0pt] options to \raisebox) so it doesn't impede in the row height - something that is naturally done by multirow.

There might be a slight discrepancy between the two methods, but it is negligible.

Related Question