# How can I vertically stretch this table to prevent line breaks in rotated text?

I've got as far as this with a table but it's obviously rather ugly as it is, especially the word "Predicted" being broken in half.

I want to "pad" the inner cells in some manner so as to allow the word "predicted" to be vertical and unbroken.

Current LaTeX code:

\usepackage{multirow}
\usepackage{makecell}
\usepackage{rotating}

\begin{table}
\centering
\begin{tabular}{llc|c|}
&                          & \multicolumn{2}{c}{Actual}  \\
&                          & \multicolumn{1}{c}{Pos} & \multicolumn{1}{c}{Neg}         \\
\cline{3-4}
\multicolumn{1}{c}{\multirow{2}{*}{\rotcell{Predicted}}} & \multicolumn{1}{r|}{Pos} & 6 TP                    & 3 FP                            \\
\cline{3-4}
\multicolumn{1}{c}{}                                     & \multicolumn{1}{r|}{Neg} & 4 FN                    & 7 TN                            \\
\cline{3-4}
\end{tabular}
\end{table}


Here's a mockup in Excel:

• Welcome to tex.sx. It would be helpful if you extend the example to start with \documentclass and end with \end{document} so potential helpers can just copy-and-paste it for experimentation. Jan 12, 2020 at 17:36

You could use the cellspace package as follows:

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

\usepackage{cellspace}

\begin{document}
\begin{table}
\setlength\cellspacetoplimit{15pt}
\setlength\cellspacebottomlimit{\cellspacetoplimit}
\centering
\begin{tabular}{llSc|Sc|}
&                          & \multicolumn{2}{c}{Actual}  \\
&                          & \multicolumn{1}{c}{Pos} & \multicolumn{1}{c}{Neg}         \\
\cline{3-4}
\multicolumn{1}{c}{\multirow{2}{*}{\rotcell[c]{Predicted}}} & \multicolumn{1}{r|}{Pos} & 6 TP                    & 3 FP                            \\
\cline{3-4}
\multicolumn{1}{c}{}                                     & \multicolumn{1}{r|}{Neg} & 4 FN                    & 7 TN                            \\
\cline{3-4}
\end{tabular}
\end{table}

\end{document}

• Perfection, I'll set as answer as soon as it lets me. Thanks so much! Jan 12, 2020 at 17:37
• Actually could you explain a little further? How do you selectively apply the padding? or is it simply that cellspace has automatically figured out that line-breaking is ugly and to expand the cells appropriately? Jan 12, 2020 at 17:44
• Actually, I achieved teh result with a little bit of try and error. With \setlength\cellspace...limit you can change the amount of vertical white space between the text and the table border. To apply the spacing, I have added S as a prefix to the column specifiers of the second last and last column of the table Sc instead of c. In addition, I have added the optional argument c to the \rotcell command. Jan 12, 2020 at 17:50

Another simple option is to increase inter-row spacing by issuing \renewcommand{\arraystretch}{1.7}, for example. I also use \rotatebox from the more-common graphicx package, which I guess you would already load for including figures in your document.

\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{multirow}

\begin{document}

\begin{table}
\renewcommand{\arraystretch}{1.7}
\begin{tabular}{llcc}
&     & \multicolumn{2}{c}{Actual}                             \\
&     & Pos                        & Neg                       \\ \cline{3-4}
\multirow{2}{*}{\rotatebox{90}{Predicted}} & Pos & \multicolumn{1}{|c|}{6 TP} & \multicolumn{1}{c|}{3 FP} \\ \cline{3-4}
& Neg & \multicolumn{1}{|c|}{4 FN} & \multicolumn{1}{c|}{7 TN} \\ \cline{3-4}
\end{tabular}
\end{table}

\end{document}