4

I am trying to make the table below:

enter image description here

I have tried the following:

\begin{tabular}{cc|cc}
\multicolumn{1}{c}{} &\multicolumn{1}{c}{} &\multicolumn{1}{c}{Predicted} \\ 
\multicolumn{1}{c}{} & 
\multicolumn{1}{c|}{} & 
\multicolumn{1}{c}{Yes} & 
\multicolumn{1}{c}{No} \\ \hline
\multirow{1}{*}{\rotatebox{90}{Actual}}
& Yes  & 100 & 0   \\ 
& No  & 10   & 80 \\ \hline
\end{tabular}

However, this gives me:

enter image description here

Notice that the labels "Predicted" and "actual" are not centered with the columns/rows below/right. In addition, the horizontal lines should stop before the "actual" label. Any suggestions?

Thanks

2
  • 1
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – dexteritas Jun 4 '18 at 7:21
  • Use \multicolumn{2}{c}{Predicted} instead of only 1, because you want it to span more than one column. – TeXnician Jun 4 '18 at 7:39
4

Here are a few ways to achive the desired result. I highly recommened using the booktabs pacakge and avoid vertical lines (as per third example):

enter image description here

Code:

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

\begin{document}
\begin{tabular}{cc|cc}
\multicolumn{1}{c}{} &\multicolumn{1}{c}{} &\multicolumn{2}{c}{Predicted} \\ 
\multicolumn{1}{c}{} & 
\multicolumn{1}{c|}{} & 
\multicolumn{1}{c}{Yes} & 
\multicolumn{1}{c}{No} \\ \hline
\multirow[c]{2}{*}{\rotatebox[origin=tr]{90}{Actual}}
& Yes  & 100 & 0   \\[1.5ex]
& No  & 10   & 80 \\ \hline
\end{tabular}
\quad% ---------------------------
\begin{tabular}{@{}cc|cc@{}}
\multicolumn{1}{c}{} &\multicolumn{1}{c}{} &\multicolumn{2}{c}{Predicted} \\ 
\multicolumn{1}{c}{} & 
\multicolumn{1}{c|}{} & 
\multicolumn{1}{c}{Yes} & 
\multicolumn{1}{c}{No} \\ 
\cline{2-4}
\multirow[c]{2}{*}{\rotatebox[origin=tr]{90}{Actual}}
& Yes  & 100 & 0   \\[1.5ex]
& No  & 10   & 80 \\ 
\cline{2-4}
\end{tabular}

\par\bigskip
\begin{tabular}{@{}cc cc@{}}
\multicolumn{1}{c}{} &\multicolumn{1}{c}{} &\multicolumn{2}{c}{Predicted} \\ 
\cmidrule(lr){3-4}
\multicolumn{1}{c}{} & 
\multicolumn{1}{c}{} & 
\multicolumn{1}{c}{Yes} & 
\multicolumn{1}{c}{No} \\ 
\cline{2-4}
\multirow[c]{2}{*}{\rotatebox[origin=tr]{90}{Actual}}
& Yes  & 100 & 0   \\[1.5ex]
& No  & 10   & 80 \\ 
\cline{2-4}
\end{tabular}
\end{document}
1
  • @Joey: Few other options now added. – Peter Grill Jun 4 '18 at 7:43
4

shorter and simpler:

  • all \multicolumn{1}{c}{...} are superfluous
  • for \rotatebox use origin=center
  • for more vertical (symmetrically distributed) spaces use macro \makegapedcells from the package makecell. it is needed for spacing rotated word "actual" in multirow cell in the first column
  • for horizontal lines are used \cline{2-4}

    \documentclass{article}
    \usepackage{graphicx}
    \usepackage{multirow}
    \usepackage{makecell} % for more vertical space in cells
    \setcellgapes{5pt}
    
    \begin{document}
    {    % for making group where "\makegapedcells" is valid
    \makegapedcells
    \begin{tabular}{cc|cc}
    \multicolumn{2}{c}{}
                &   \multicolumn{2}{c}{Predicted} \\
        &       &   Yes &   No              \\ 
        \cline{2-4}
    \multirow{2}{*}{\rotatebox[origin=c]{90}{Actual}}
        & Yes   & 100   & 0                 \\
        & No    & 10    & 80                \\ 
        \cline{2-4}
        \end{tabular}
     }
     \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.