0

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.

An ugly table with 90 degree text broken in half to fit in the short vertical space

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:

enter image description here

1
  • 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

2 Answers 2

1

You could use the cellspace package as follows:

enter image description here

\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}
3
  • Perfection, I'll set as answer as soon as it lets me. Thanks so much!
    – ch4rl1e97
    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?
    – ch4rl1e97
    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.
    – leandriis
    Jan 12, 2020 at 17:50
1

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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.