2
\documentclass[12pt,a4paper]{book} 
\usepackage{array} 
\begin{document}
\begin{table}[H]
\setlength{\tabcolsep}{5mm}
\begin{tabular}[h]{|>{\centering\arraybackslash}p{2cm}||>      {\centering\arraybackslash}p{3cm}|>{\centering\arraybackslash}p{2cm}|>{\centering\arraybackslash}p{1cm}|>{\centering\arraybackslash}p{2.5cm}|} 
\hline
\rotatebox{90} {\centering case1}      & \rotatebox{90}{\centering Case2}   &  \rotatebox{90}{\centering This is the case 3?} & \rotatebox{90} {\centering Case 4}  \\ \hline\hline
a      &  b    & c  & d  \\ \hline 
\end{tabular}
\caption{My table}
\end{table}
\end{document}

How can I split the title "This is the case 3" into two lines?

researcher
  • 4,555

2 Answers2

4

One way would be to use something like

\parbox{2cm}{\raggedright This is the case 3?}

or add a \\ to manually split the line:

\parbox{2cm}{\raggedright This is \\ the case 3?}

enter image description here

Code:

\documentclass{article}
\usepackage{array}
\usepackage{graphicx}
\begin{document}
\setlength{\tabcolsep}{5mm}
\begin{tabular}[h]{|>{\centering\arraybackslash}p{2cm}||>      {\centering\arraybackslash}p{3cm}|>{\centering\arraybackslash}p{2cm}|>{\centering\arraybackslash}p{1cm}|>{\centering\arraybackslash}p{2.5cm}|} 
\hline
\rotatebox{90} {\centering case1}      & \rotatebox{90}{\centering Case2}   &  
\rotatebox{90}{\centering \parbox{2cm}{\raggedright This is the case 3?}} & \rotatebox{90} {\centering Case 4}  \\ \hline\hline
a      &  b    & c  & d  \\ \hline 
\end{tabular}

\begin{tabular}[h]{|>{\centering\arraybackslash}p{2cm}||> {\centering\arraybackslash}p{3cm}|>{\centering\arraybackslash}p{2cm}|>{\centering\arraybackslash}p{1cm}|>{\centering\arraybackslash}p{2.5cm}|} \hline \rotatebox{90} {\centering case1} & \rotatebox{90}{\centering Case2} &
\rotatebox{90}{\centering \parbox{2cm}{\raggedright This is \ the case 3?}} & \rotatebox{90} {\centering Case 4} \ \hline\hline a & b & c & d \ \hline \end{tabular} \end{document}

Peter Grill
  • 223,288
  • Did you mean \rotatebox{90}\parbox{2cm}{\centering \raggedright This is the case 3?} ? it didn't work ;( – researcher Nov 21 '12 at 10:28
  • 1
    Can you first complete your code snippet in the question so that I can cut and paste and get it to compile. That way I can be sure I am using the same packages as you. – Peter Grill Nov 21 '12 at 10:32
  • \rotatebox{90}{\parbox{2cm}{ This is \ the case 3?}} it works :) – researcher Nov 21 '12 at 10:42
  • thank you for answer, please i have one more question: how can i divide a line in a cellule ? simple cellule not the title. – researcher Dec 03 '12 at 18:35
  • @researcher: If I understand you correctly you could either use the p{} column type, as in the example here in which case it should already wrap. Or, use a \parbox{<length>}{} for the content. If that does not work, then you should post a separate question as it is not related to the title of this question. And as I am not quite the expert as some other people here, so I would have to actually see the table and try things to find the ideal solution. – Peter Grill Dec 03 '12 at 19:17
  • i have added \newline between words and it works :) – researcher Dec 03 '12 at 19:24
4

The \centering in

 \rotatebox{90}{\centering This is the case 3?}

is doing nothing, it is like

 \mbox{\centering This is the case 3?}

In both cases there is a single TeX horizontal (LR) box in which no linebreaking happens.

Depending on the appearance that you want any of the following work and give different effects


\rotatebox{90}{\parbox{2cm}{\centering This is the\\ case 3?}}

\rotatebox{90}{\parbox{2cm}{This is the\\ case 3?}}

\rotatebox{90}{This is the}
\rotatebox{90}{case 3?}}

David Carlisle
  • 757,742