# How to wrap text in table cell?

this code:

%%%%%%%%%%%%%%%%%%Table: Valence  x valence crosstab
\begin{table*}[t]
\centering
\begin{tabular}{c c c c c c c}
\toprule
\midrule
& & \multicolumn{5}{c}{Predicted valence }\\ \cmidrule{3-7}
&& Negative  & Little negative & Neutral & Little positive & Positive  \\ \cmidrule{3-7}
\multicolumn{1}{c}{\multirow{5}{*}{\begin{sideways}Actual valence\end{sideways}}}   &
\multicolumn{1}{l}{Negative}& 59.0 & 18.0 & 17.3 & 5.8 &  \\
\multicolumn{1}{c}{}    &
\multicolumn{1}{l}{Little negative}& 0.9 & 66.6 & 16.7 & 10.7 & 5.1  \\
\multicolumn{1}{c}{}    &
\multicolumn{1}{l}{Neutral} &1.4 & 16.6 & 70.8 & 8.0 & 3.1  \\
\multicolumn{1}{c}{}    &
\multicolumn{1}{l}{Little positive} &0.3 & 11.2 & 20.0 & 68.0 & .5  \\
\multicolumn{1}{c}{}    &
\multicolumn{1}{l}{Positive} & 4.9 & 7.8 & 17.5 & 69.9  \\
\midrule
\bottomrule
\end{tabular}
\centering
\caption{Classification results for the valence dimension.}
\label{tab:sam_count}
\end{table*}
%%%%%%%%%%%%%%%%%


prduces this:

I want the vertical text "actual valence" to have an newline in between.

How to I accomplish this?

-

One option would be to use a \parbox:

\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{rotating}

\begin{document}

\begin{table*}[t]
\centering
\begin{tabular}{c c c c c c c}
\toprule
\midrule
& & \multicolumn{5}{c}{Predicted valence }\\ \cmidrule{3-7}
&& Negative  & Little negative & Neutral & Little positive & Positive  \\ \cmidrule{3-7}
\multicolumn{1}{c}{\multirow{5}{*}{\begin{sideways}\parbox{2cm}{\centering Actual \\ valence}\end{sideways}}}   &
\multicolumn{1}{l}{Negative}& 59.0 & 18.0 & 17.3 & 5.8 &  \\
\multicolumn{1}{c}{}    &
\multicolumn{1}{l}{Little negative}& 0.9 & 66.6 & 16.7 & 10.7 & 5.1  \\
\multicolumn{1}{c}{}    &
\multicolumn{1}{l}{Neutral} &1.4 & 16.6 & 70.8 & 8.0 & 3.1  \\
\multicolumn{1}{c}{}    &
\multicolumn{1}{l}{Little positive} &0.3 & 11.2 & 20.0 & 68.0 & .5  \\
\multicolumn{1}{c}{}    &
\multicolumn{1}{l}{Positive} & 4.9 & 7.8 & 17.5 & 69.9  \\
\midrule
\bottomrule
\end{tabular}
\centering
\caption{Classification results for the valence dimension.}
\label{tab:sam_count}
\end{table*}

\end{document}


-

Another option to using a parboxas @GonzaloMedina suggested is to abandon the rotated \multirow and use trimmed cmidrules for a more "traditional" table head.

\documentclass[a4paper]{article}

\usepackage{rotating,booktabs,multirow}

\begin{document}
\begin{table*}[t]
\centering
\begin{tabular}{c c c c c c}
\toprule
\midrule
\multirow{2}[4]{*}{Actual Valence} & \multicolumn{5}{c}{Predicted valence }\\ \cmidrule(rl){2-6}
& Negative  & Little negative & Neutral & Little positive & Positive  \\ \cmidrule(r){1-1}\cmidrule(l){2-6}
\multicolumn{1}{l}{Negative}& 59.0 & 18.0 & 17.3 & 5.8 &  \\
\multicolumn{1}{l}{Little negative}& 0.9 & 66.6 & 16.7 & 10.7 & 5.1  \\
\multicolumn{1}{l}{Neutral} &1.4 & 16.6 & 70.8 & 8.0 & 3.1  \\
\multicolumn{1}{l}{Little positive} &0.3 & 11.2 & 20.0 & 68.0 & .5  \\
\multicolumn{1}{l}{Positive} & 4.9 & 7.8 & 17.5 & 69.9  \\
\midrule
\bottomrule
\end{tabular}
%\centering
\caption{Without rotation, with trimmed cmidrules}
\label{tab:sam_count2}
\end{table*}
\end{document}


-
Very nice. The only thing I'd change is that the first cmidrule doesn't need to be trimmed at the right-hand end. (See also the length of the second long cmidrule.) –  Mico Aug 15 '12 at 0:05

It's almost always an inferior idea to force the reader to crane his/her neck 90 degrees in order to read some header line. In the present table, I can't see a good reason for inflicting this inconvenience on the readers, especially as the first column's header ("Actual valence") is almost exactly as wide as the longest entry in that column ("Little negative").

I'd rather expend some extra effort on aligning all numbers neatly on their decimal points, because this does tend to facilitate comprehension of the contents of a table. In the modified MWE below, this is done using the siunitx package and its S column type.

\documentclass{article}
\usepackage{booktabs,siunitx}
\sisetup{table-format=2.1}
\begin{document}

\begin{table}[t]
\centering
\begin{tabular}{@{} l SSSSS @{}} % @{} serves to suppress white space at ends of table
\toprule
Actual valence   &  \multicolumn{5}{c @{}}{Predicted valence }\\
\cmidrule(l){2-6}
& {Negative} & {Little negative} & {Neutral} & {Little positive} & {Positive}  \\
\midrule
Negative        & 59.0 & 18.0 & 17.3 &  5.8 &  \\
Little negative &  0.9 & 66.6 & 16.7 & 10.7 & 5.1  \\
Neutral         &  1.4 & 16.6 & 70.8 &  8.0 & 3.1  \\
Little positive &  0.3 & 11.2 & 20.0 & 68.0 &  .5  \\
Positive        &  4.9 &  7.8 & 17.5 & 69.9 & \\
\bottomrule
\end{tabular}
\caption{Classification results for the valence dimension.}
\label{tab:sam_count}
\end{table}
\end{document}

-
The S-columns are a very useful addition. –  hakaze Aug 15 '12 at 7:34
will go for this option, looks much neater, selected the other answer though, since it answers the question –  jorrebor Aug 15 '12 at 8:01