111

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

David Carlisle
  • 757,742
Isai
  • 4,153

5 Answers5

166

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]).

CarLaTeX
  • 62,716
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

AboAmmar
  • 46,352
  • 4
  • 58
  • 127
11

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

Seong
  • 161
5

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

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

Hope it helps..

Found here

Pontios
  • 249
  • 3
  • 6
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

F. Pantigny
  • 40,250