2

I am trying to create this table on latex

enter image description here

however I dont know how to use multi row.Here is my code

\begin{center}
\centering
 \begin{tabular}{ | l | l | l | l | l | }
 \hline 
   & & \multicolumn{3}{|c|}{ACTUAL}  \\ \hline
   &  &Class A & Class B  & Class C     \\ \hline
   &   Class A & 42 & 4 & 3     \\ \hline
  &   Class B & 11 & 35 & 2    \\ \hline
   &  Class C & 3 & 6 & 38    \\ \hline


    \end{tabular}
    \captionof{table}{Risk Matrix} 
\end{center}

And this what i get with the code

enter image description here

Note: and how can i center the value in table

allstar
  • 45

4 Answers4

4
\documentclass[12pt]{article}
\usepackage{multirow,graphicx}
\usepackage{caption}
\begin{document}
\begin{center}
\centering
\renewcommand\arraystretch{1.1}
 \begin{tabular}{ | l | l | l | l | l | }
 \cline{3-5}
   \multicolumn{2}{c|}{}& \multicolumn{3}{|c|}{ACTUAL}  \\ \cline{3-5}
   \multicolumn{2}{c|}{} &Class A & Class B  & Class C     \\ \hline
  \multirow{3}{*}{\rotatebox{90}{\tiny ESTIMATED\,}} & Class A & 42 & 4 & 3\\ \cline{2-5}
  &   Class B & 11 & 35 & 2    \\ \cline{2-5}
   &  Class C & 3 & 6 & 38    \\ \hline
    \end{tabular}
    \captionof{table}{Risk Matrix} 
\end{center}
\end{document}

enter image description here

4
\documentclass{scrartcl}
    \usepackage{array,multirow,graphicx,booktabs}

\begin{document}
    \begin{center}
        \centering
        \begin{tabular}{  l  l  c  c  c  }
            \toprule
            & & \multicolumn{3}{c}{\textbf{Actual}}  \\ 
            &  &Class A & Class B  & Class C     \\ 
            \midrule
            \parbox[t]{2mm}{\multirow{3}{*}{\rotatebox[origin=c]{90}{\textbf{Estim.}}}}&   Class A & 42 & 4 & 3     \\ 
            &   Class B & 11 & 35 & 2    \\ 
            &  Class C & 3 & 6 & 38    \\ 
            \bottomrule

        \end{tabular}
        \captionof{table}{Risk Matrix} 
    \end{center}
\end{document}

enter image description here

ebosi
  • 11,692
  • oops, didn't noticed Steven's answer before posting. moreover, this answer does not address what OP were asking... However, this is a suggestion for another (better ?) layout. – ebosi May 09 '16 at 13:06
2

Here are 3 variants, using siunitx for the centred-right aligned numbers, and different possible rules with hhline, booktabs and/or boldline:

\documentclass[12pt]{article}
\usepackage{multirow,graphicx}
\usepackage{caption}
\usepackage{array, siunitx, boldline, hhline, booktabs}


 \begin{document}

\begin{center}
\centering\sisetup{table-format=2.0}
\renewcommand\arraystretch{1.25}\setlength\arrayrulewidth{1pt}
 \begin{tabular}{c|l *{3}{V{0.3}S}|}
   \multicolumn{2}{c}{}& \multicolumn{3}{c}{ACTUAL} \\
  \hhline{~~|---}
   \multicolumn{2}{c|}{} & {Class A} & {Class B} & {Class C} \\
  \hhline{~|----|}%\clineB{3-5}{0.3}
  \multirow{3}{*}[-0.2ex]{\rotatebox{90}{\scriptsize ESTIMATED\,}} & Class A & 42 & 4 & 3\\ \clineB{2-5}{0.3}
  & Class B & 11 & 35 & 2 \\ \clineB{2-5}{0.3}
   & Class C & 3 & 6 & 38 \\
   \hhline{~|----}
    \end{tabular}
    \captionof{table}{Risk Matrix}
\end{center}

\begin{center}
\centering\sisetup{table-format=2.0}
\renewcommand\arraystretch{1.25}\setlength\arrayrulewidth{1pt}
 \begin{tabular}{cl| *{3}{S}}
    \multicolumn{2}{c}{} & \multicolumn{3}{c}{ACTUAL} \\
    & & {Class A} & {Class B} & {Class C} \\
 \cline{2-5}
  \multirow{3}{*}[-0.2ex]{\rotatebox{90}{\scriptsize ESTIMATED\,}} & Class A & 42 & 4 & 3\\ %
  & Class B & 11 & 35 & 2 \\ %
   & Class C & 3 & 6 & 38 \\
    \end{tabular}
    \captionof{table}{Risk Matrix}
\end{center}

\begin{center}
\centering\sisetup{table-format=2.0}
 \begin{tabular}{cl *{3}{S}}
    & & \multicolumn{3}{c}{ACTUAL} \\
\cmidrule(l{-1.5em}r{-1.5em}){4-4}
    & & {Class A} & {Class B} & {Class C} \\%
    \cmidrule[\heavyrulewidth]{2-5}
    \multirow{3}{*}{\rotatebox{90}{\scriptsize ESTIMATED\,}} & Class A & 42 & 4 & 3\\ \addlinespace
  & Class B & 11 & 35 & 2 \\ \addlinespace
   & Class C & 3 & 6 & 38 \\
    \cmidrule[\heavyrulewidth]{2-5}
\addlinespace[-\belowrulesep]
    \end{tabular}
    \captionof{table}{Risk Matrix}
\end{center}

\end{document} 

enter image description here

Bernard
  • 271,350
1

You can easily do that table with {NiceTabular} of nicematrix. The key hvlines draws all the rules, excepted in the 'corners'. With the key corners, we have told nicematrix to take into consideration the corner north-west (NW).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\renewcommand{\arraystretch}{1.2} \begin{NiceTabular}{>{\tiny}ccccc}[corners=NW,hvlines] & & \Block{1-3}{ACTUAL} \ & & Class A & Class B & Class C \ \Block{3-1}{\rotate ESTIMATED} & Class A & 42 & 4 & 3 \ & Class B & 11 & 35 & 2 \ & Class C & 3 & 6 & 38 \end{NiceTabular}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

F. Pantigny
  • 40,250