1

I know using turn command and a sample code like this:

\usepackage{rotating}

\begin{turn}{90} Supervised Learning \end{turn}}

we can rotate a text inside a cell, however, I couldn't find a way to vertically center this rotated text. Any suggestions is appreciated.

Here is the sample MWE:

\begin{table}[]
    \centering
    \begin{tabular}{|>{\centering\arraybackslash}m{0.5cm}|c|>{\centering\arraybackslash}m{8cm}|}
        \hline
        \multicolumn{2}{|c|}{Classification} & References \\ \hline
        %\multirow{2}{*}{{\begin{turn}{90}Supervised Learning\end{turn}}}   
        \multirow{2}{*}{\rotatebox[origin=c]{90}{Supervised Learning}} 
\end{tabular}
    \caption{A Classification}
    \label{tab:Machine_Learning_models}
\end{table}

enter image description here

Amir
  • 351
  • Maybe some here know this package ... however, to other will help a MWE (small complete document, which we can compile), which will show your problem. – Zarko Aug 28 '16 at 18:57
  • my bad, it was called rotating – Amir Aug 28 '16 at 19:16
  • 1
    I have updated the question with a MWE – Amir Aug 28 '16 at 19:36
  • 2
    Your subject and objective of your updated question is radically different from what you asked originally. Instead of editing an existing question and changing its content dramatically, you should consider leaving the original query unchanged and posting a second, new query to address the new subject material. If nothing else, this approach would avoid rendering the answer that was addressed the initial version of your query meaningless and inapplicable. – Mico Aug 28 '16 at 19:47
  • My question was on how to vertically center a rotated text and my question is still that one. – Amir Aug 28 '16 at 19:56
  • @Amir - I've deleted my answer. It is obviously of no relevance to your highly modified query. – Mico Aug 28 '16 at 20:06
  • Sorry for the confusion. This has been driving me crazy for hours. Even here doesn't work: http://tex.stackexchange.com/questions/166482/how-to-horizontally-align-rotated-text-in-a-table – Amir Aug 28 '16 at 20:13
  • @Mico, I have created a new question with full code here: http://tex.stackexchange.com/questions/326915/vertically-align-a-multirow-text-which-has-been-rotated – Amir Aug 28 '16 at 20:26

1 Answers1

6

since your question seems to be unstable system ... i'm afraid that my answer will miss your point as it was Mico answer (which finish with deletion) :-( )

anyway, for exercise:

  • your rotated text is taller than rest of table, so it can not bo properly centered
  • easier way to rotate cell content is use \rothead macro from makecell package (for which you need to define cell height)
  • vertically centering in multirow cell needs some manual tweaking

with this (and expand the table) I obtain the following result:

enter image description here

MWE:

\documentclass{article}
\usepackage{rotating}
\usepackage{array,makecell,multirow}

\begin{document}
\begin{table}[htb]
    \centering
    \settowidth\rotheadsize{Supervised Learning}
    \begin{tabular}{| l | c |
                     >{\centering\arraybackslash}p{8cm}|}
    \hline
\multicolumn{2}{|c|}{Classification}    &   References  \\ \hline
\multirow{8}{*}[1.5ex]{\rothead{Supervised Learning}}  
        &                               &  1            \\ \cline{2-3}
        &                               &  2            \\ \cline{2-3}
        &                               &  3            \\ \cline{2-3}
        &                               &  4            \\ \cline{2-3}
        &                               &  5            \\ \cline{2-3}
        &                               &  6            \\ \cline{2-3}
        &                               &  7            \\ \cline{2-3}
        &                               &  8            \\ \hline                \end{tabular}
\caption{A Classification}
    \label{tab:Machine_Learning_models}
\end{table}
\end{document}

Addendum: Font size of text in \rothead is determined by \headfont macro. Default value is \footnotesize. It can be changed by

\renewcommand\theadfont{\normalsize}

(or whatever size, font family and shape you like). Considering above change of font size, the relvant part of MWE become:

\documentclass{article}
\usepackage{rotating}
\usepackage{array,makecell,multirow}
\renewcommand\theadfont{\normalsize}% <-- added

\begin{document}
\begin{table}[htb]
    \centering
    \settowidth\rotheadsize{\theadfont Supervised Learning}% <-- changed
    \begin{tabular}{| l | c |
                     >{\centering\arraybackslash}p{8cm}|}
    \hline
\multicolumn{2}{|c|}{Classification}    &   References  \\ \hline
\multirow{8}{*}{\rothead{Supervised Learning}}% <-- changed
% further is the same as in above MWE

and table will looks as follows:

enter image description here

Zarko
  • 296,517
  • Thanks for suggesting makecell package. Could you ellaborate more on the \settowidth\rotheadsize{Supervised Learning} and that [1.5ex] in the command. – Amir Aug 28 '16 at 20:51
  • and the other thing is that it seems to reduce the text size tho I have plenty of space to have it the normal size. Should I manually increase it ? – Amir Aug 28 '16 at 20:56
  • 1
    all is explained in answer ...\settowidth\rotheadsize{Supervised Learning} determine the length of text, which rotated should fit into cell. i.e. determine cell height. [1.ex] in multirow is manual adjustment of vertical position of cell content. sorry, i do not understand the second comment. which size is reduced? if you like to have table width equal to text width (i guessing) than the best way to achieve this is use of tabularx instead of table where instead p{...} you use X column type. – Zarko Aug 28 '16 at 21:06
  • Thanks @Zarko. My 2nd question was about the text of the {Supervised Learning} is now being reduced in font size despite having enough of space in the column. The vertical alignment is OK now after manually setting [1.ex] – Amir Aug 29 '16 at 13:00
  • 1
    Indeed, the fonts for vertical text is smaller. It is defined by \theadfont which default size is \footnotesize. to increase it you need to add \renewcommand\theadfont{\normalsize}( or whatever size, font family and shape you like). I will edit my answer. – Zarko Aug 29 '16 at 13:52
  • Thanks @Zarko for clarification. Just one thing and it is the issue I have by setting determine cell height to some extreme values such as -10 or 20, i.e., [-10ex]. This is needed to center the text, but this will put empty lines of ex for the first nested row. Any ideas why ? To clarify for on your given MWE, it will add empty line at the end of the your first row which has nested by Supervised Learning and beneath Classification. – Amir Aug 30 '16 at 16:33
  • I have tested all three rotation methods (turn, rothead and rotatebox) and all has the same problem with setting high values. Apparently your approach didn't solve the question. Setting \multirow{8}{*}[<ANY_DIGIT>ex]{\rothead{text}} is only good enough till the threshold of the first nested row (the height of the 1st nested row) for all mentioned methods. Any values more than that will cuz empty lines. :| – Amir Aug 30 '16 at 16:43
  • all my rest show, that rothead work as advertised. if you not satisfied with this, than consider to redesign you table so, that rotating text is no needed (or invent/write new package which will work better). – Zarko Aug 30 '16 at 18:13
  • If you fill up your nested rows on column 2 with so many text, you will see what the problem is. I guess it has nothing to do with wither of the packages but with that cell height alignment of the multirow package. So your answer still holds @Zarko – Amir Aug 30 '16 at 18:38
  • One option (when the rotated text is to tall) is to broke rotated text into two (or more) lines (if this acceptable option). – Zarko Aug 30 '16 at 18:59