112

I have a big table with a problem, when I want to rotate the text in a \multirow cell, the text is placed outside and is bigger than the dimensions of the cell, I took some advice from here, using\parbox, and then \rotatebox. But I don't get good results.

 \documentclass{article}
 \usepackage{array,multirow,graphicx}
 \begin{document}
 \begin{table}[H]
 \centering
 \begin{tabular}{|c|l|r|r|r|r|}
 \hline
 & \multicolumn{1}{|c|}{Text} & \multicolumn{1}{|c|}{Text} & \multicolumn{1}{|c|}{Text} & \multicolumn{1}{|c|}{Text} & \multicolumn{1}{|c|}{text}\\
 \hline
 \rotatebox{90}{\parbox{2mm}{\multirow{3}{*}{rota}}} & text &&&&\\
 & text &&&&\\
 & text &&&&\\
 \hline
 \end{tabular}
 \end{table}
 \end{document}

Which results in:

rotate problem

5 Answers 5

169

Put \rotatebox inside like:

\parbox[t]{2mm}{\multirow{3}{*}{\rotatebox[origin=c]{90}{rota}}}

Code:

 \documentclass{article}
 \usepackage{array,multirow,graphicx}
 \usepackage{float}
 \begin{document}
 \begin{table}[H]
 \centering
 \begin{tabular}{|c|l|r|r|r|r|}
 \hline
 & \multicolumn{1}{c|}{Text} & \multicolumn{1}{c|}{Text} & \multicolumn{1}{c|}{Text} & \multicolumn{1}{c|}{Text} & \multicolumn{1}{c|}{text}\\
 \hline
 \parbox[t]{2mm}{\multirow{3}{*}{\rotatebox[origin=c]{90}{rota}}} & text &&&&\\
 & text &&&&\\
 & text &&&&\\
 \hline
 \end{tabular}
 \end{table}
 \end{document}

enter image description here

I have eliminated some spurious vertical lines in the title and introduced the origin for rotation. However, the idea of introducing a parbox did not get in to my head as this may not be needed for the present MWE. In case you have other uses in your actual code, you may use the alignment specifiers to parbox (Here [t]).

5
  • If rota is instead rotatoata, it will be outside the table. Any idea of how to force it to increase the spacing of rows or something to avoid this? Commented Oct 15, 2015 at 14:10
  • 1
    @J.C.Leitão You can't. Only way is to increase the number of rows from 3 to 4 or more.
    – user11232
    Commented Oct 15, 2015 at 14:14
  • For posterity, an hacky solution is to decrease the text-size. Commented Oct 15, 2015 at 14:15
  • Note that with colors it is safer to use the last row to contain the multirow, see this blog
    – towi
    Commented Sep 27, 2016 at 21:06
  • 2
    I can confirm that \parbox does not seem necessary
    – Johannes
    Commented Nov 1, 2019 at 9:25
24

A variant that doesn't require manual adjustment of width and automatically centers the rotated cell horizontally:

\documentclass{article}
\usepackage{array,multirow,graphicx}
\begin{document}

\newcommand{\STAB}[1]{\begin{tabular}{@{}c@{}}#1\end{tabular}}

\begin{table}[!h]
  \centering
  \begin{tabular}{|c|l|r|r|r|r|}
    \hline
     & \multicolumn{1}{c|}{Text} & \multicolumn{1}{c|}{Text} & \multicolumn{1}{c|}{Text} & \multicolumn{1}{c|}{Text} & \multicolumn{1}{c|}{text} \\ \hline
     \multirow{3}{*}{\STAB{\rotatebox[origin=c]{90}{rota}}}
     & text                      &                           &                           &                           &                           \\
     & text                      &                           &                           &                           &                           \\
     & text                      &                           &                           &                           &                           \\ \hline
  \end{tabular}
\end{table} 

\end{document}

enter image description here

1
  • 3
    It seems to work without STAB too for me: \multirow{3}{*}{\rotatebox[origin=c]{90}{rota}}. Not sure what it is for. Commented Dec 8, 2020 at 15:18
12

Improving Harish Kumar's answer on follow up question of placing longer word inside a cell, i.e., rota to rotatoata. It also uses \rotatebox and \parbox but the order is different.

And, if the intentions of using \multicolumn{1}{c|}{Text} is to center the text, then {\hfill Text\hfill} could be alternative solution.

Code:

\documentclass{article}
\usepackage{array,multirow,graphicx}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{|c|l|r|r|r|r|}\hline
~ & \multicolumn{1}{c|}{Text} & {\hfill Text\hfill} & \multicolumn{1}{c|}{Text} & \multicolumn{1}{c|}{Text} & \multicolumn{1}{c|}{Text} \\ \hline
\multirow{3}{*}{\rotatebox[origin=c]{90}{\parbox[c]{1cm}{\centering rotato-ata}}} & text &&&&\\
& text &testing A& testing B&&\\
& text &right aligned&&&\\ \hline
\end{tabular}
\end{table}
\end{document}

result

1
  • 1
    Updated the package from graphics to graphicx and it works. Checked with Overleaf.
    – Seong
    Commented Jan 1, 2018 at 9:20
5

add \newcommand*\rot{\rotatebox{90}} before \begin{document}

and then just do \rot{Whatever you want to rotate}

Hope it helps..

Found here

4

With {NiceTabular} of nicematrix and its built-in command \Block, you have directly the expected output.

Morever, with that command \Block, you specify the number of logical rows and not the number of physical row (as with \multirow).

 \documentclass{article}
 \usepackage{nicematrix}

 \begin{document}
 \begin{table}[!h]
   \centering
   \begin{NiceTabular}{|c|l|r|r|r|r|}
     \hline
      & Text & Text & Text & Text & text \\ \hline
      \Block{3-1}<\rotate>{rota}
      & text & & & & \\
      & text & & & & \\
      & text & & & & \\ \hline
   \end{NiceTabular}
 \end{table} 
 \end{document}

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

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .