4

I have problems creating a table whose headline is split the following way:

enter image description here

I also don't know how to effectively visualize multiple confusion matrices for all my eleven datasets. A confusion matrix represents the amount of samples that were recognized as positive or negative. It also takes into account if those classification are right or wrong. In the end you get true positives, false positives, true negatives, and false negatives. imagined something like that:

enter image description here

Any help is appreciated.

1
  • 4
    Welcome to TeX.SE :) // Latex is powerful, which gives confusion to the novice. I suggest doing in parallel: a) getting one of those big books on Latex introduction, at least this one online: en.wikibooks.org/wiki/LaTeX, b) do a search for tables here, e.g. via your tag, or via the right column under "Related".
    – MS-SPO
    Commented Sep 30, 2021 at 5:35

2 Answers 2

6

enter image description here

\documentclass{article}
\usepackage{nicematrix}
\usepackage{makecell}

\begin{document}
    

    \begin{table}
        \caption{The Caption}
        \centering
        \begin{NiceTabular}{*{7}{c}}[vlines,cell-space-limits=3pt]
            \Hline
            &\Block{1-2}{D1}
                &
                    &\Block{1-2}{D2}
                        &
                            &\Block{1-2}{D3}
                                &               \\\Hline
            &P
                &N
                    &P
                        &N
                            &P
                                &N              \\\Hline
            P&1&2&3&4&5&6                       \\\Hline                    
            N&1&2&3&4&5&6                       \\\Hline
        \end{NiceTabular}
    \end{table}
\end{document}

OR

\documentclass{article}
\usepackage{nicematrix}
\usepackage{makecell}

\begin{document}
    

    \begin{table}
        \caption{The Caption}
        \centering
        \begin{NiceTabular}{*{7}{c}}[vlines,cell-space-limits=3pt]
            \Hline
            &\Block{1-2}{D1}
                &
                    &\Block{1-2}{D2}
                        &
                            &\Block{1-2}{D3}
                                &               \\\Hline
            &P
                &N
                    &P
                        &N
                            &P
                                &N              \\\Hline
            P&1&2&3&4&5&6                       \\\Hline                    
            N&1&2&3&4&5&6                       \\\Hline
            &\Block{1-2}{D4}
                &
                    &\Block{1-2}{D5}
                        &                       \\\Hline
            &P
                &N
                    &P
                        &N                      \\\Hline
            P&1&2&3&4                       \\\Hline                    
            N&1&2&3&4                       \\\Hline
        \end{NiceTabular}
    \end{table}
\end{document}

enter image description here

2
  • 2
    Hello, do you also know how to create the first table in my question? I would really appreciate it if you helped me with that, too. Commented Sep 30, 2021 at 9:27
  • 2
    may I request a separate question for attracting a larger audience
    – js bibra
    Commented Sep 30, 2021 at 10:36
4

MWE

\documentclass[12pt]{article}
\usepackage{color}
\usepackage{array}
\usepackage{float}
\usepackage{multirow}

\providecommand{\tabularnewline}{\\}

\begin{document}
\begin{tabular}{|c|c|c|c|c|}
\hline 
\multirow{2}{*}{Dataset} & \multicolumn{2}{c|}{M1} & \multicolumn{2}{c|}{M2}\tabularnewline
\cline{2-5} \cline{3-5} \cline{4-5} \cline{5-5} 
 & X & Y & X & Y\tabularnewline
\hline 
D1 &  &  &  & \tabularnewline
\hline 
D2 &  &  &  & \tabularnewline
\hline 
D3 &  &  &  & \tabularnewline
\hline 
D4 &  &  &  & \tabularnewline
\hline 
\multirow{2}{*}{Dataset} & \multicolumn{2}{c|}{M3} & \multicolumn{2}{c|}{M4}\tabularnewline
\cline{2-5} \cline{3-5} \cline{4-5} \cline{5-5} 
 & X & Y & X & Y\tabularnewline
\hline 
D5 &  &  &  & \tabularnewline
\hline 
D6 &  &  &  & \tabularnewline
\hline 
D7 &  &  &  & \tabularnewline
\hline 
D8 &  &  &  & \tabularnewline
\hline 
\end{tabular}

\end{document}

enter image description here

Not the answer you're looking for? Browse other questions tagged .