Search code examples
pdflatextabular

Create a table with double title


I have this code to create a table, but I want to create a table like the image below. How can I modify the code to create the table?

\begin{tabular}{|l|l|l|l|l|}
\hline
   & AB & A & B & O \\ \hline
AB & 0  & 1 & 1 & 2 \\ \hline
A  & 1  & 0 & 2 & 2 \\ \hline
B  & 1  & 2 & 0 & 2 \\ \hline
O  & 3  & 3 & 3 & 0 \\ \hline
\end{tabular}
\end{table}

Table


Solution

  • Hopefully easy:

    \documentclass{article}
    \usepackage{multirow}
    
    \begin{document}
    
    \begin{table}
    \centering
    \begin{tabular}{cc|c|c|c|c|}
     & \multicolumn{1}{c}{ } & \multicolumn{4}{c}{Classified As} \\
     &                       & AB & A & B & O \\ \cline{2-6}
    \multirow{4}{11mm}{True Blood Type} %
     & AB                    & 0  & 1 & 1 & 2 \\ \cline{2-6}
     & A                     & 1  & 0 & 2 & 2 \\ \cline{2-6}
     & B                     & 1  & 2 & 0 & 2 \\ \cline{2-6}
     & O                     & 3  & 3 & 3 & 0 \\ \cline{2-6}
    \end{tabular}
    \end{table}
    
    \end{document}
    

    The above MWE outputs the following table:

    Screenshot of output

    This first sketch can then be improved aesthetically in several ways!