17

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.

5
  • 1
    Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Sep 17, 2014 at 16:44
  • I think, you are after \rotatebox from graphicx package
    – user31729
    Sep 17, 2014 at 16:44
  • @ChristianHupfer The code is there. Could you please elaborete?
    – Carl Mill
    Sep 17, 2014 at 16:45
  • 1
    It's a fragment, not a MWE ;-)
    – user31729
    Sep 17, 2014 at 16:46
  • A MWE contains ideally a code that runs: I can't feed a \begin{tabular} stuff to LaTeX without document around it. So it's a fragment of something that could work ;-)
    – user31729
    Sep 17, 2014 at 16:49

3 Answers 3

25

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.

5

As mentioned by @Christian Hupfer, you can do that with rotatebox. But maybe, depending on the real contents, aesthetically, you'll prefer the vertical text ‘rule-free’. Some adjusment is often necessary to ensure vertical centring:

\documentclass{article}

\usepackage{multirow}
\usepackage{mathtools}
\usepackage{array, caption}
\usepackage{graphicx}
\usepackage{makecell}

\begin{document}

\begin{tabular}{ |c|c|c| }
\hline
\multirow{8}{*}[-0.4ex]{\rotatebox{90}{Some 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}
\hskip 1 cm
\begin{tabular}{ c|c|c| }
\cline{2-3}
\multirow{8}{*}[-0.4ex]{\rotatebox{90}{Some 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 \\
 \cline{2-3}
\end{tabular}

\end{document} 

enter image description here

7
  • How do you reduce the spacing on top of and below "Some Text". I tried doing it with a block of text that is on two lines and adjusting the column width causes strange things to happen.
    – Veridian
    Apr 13, 2016 at 23:42
  • @Veridian: I'm afraid I don't understand what you mean with ‘reducing’ – for me, there's nothing to reduce since there are 8 rows. Could give some more details?
    – Bernard
    Apr 13, 2016 at 23:47
  • @Veridian: Maybe you mean the space which is physically on the left and on the right?
    – Bernard
    Apr 13, 2016 at 23:50
  • Yeah, I want the column width to be reduced, but just the first column.
    – Veridian
    Apr 13, 2016 at 23:50
  • Because you have rotated text on two lines?
    – Bernard
    Apr 13, 2016 at 23:51
1

With {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{|c|c|c|}
\hline
\Block{8-1}{\rotate 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{NiceTabular} 

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.