3

Okay, so I'm trying to make this sort of a table:

----------------------------
|                  A       |
|     &       true   false |
|           |--------------|
| B | true  |  1       1   |
|   | false |  2       3   |
|--------------------------|

and this is my code.

\begin{tabular}{|cccc|}
\hline
\multicolumn{2}{c}{\multirow{2}{*}{\&}} & & A
 & & true & false
\multirow{2}{*}{B} & false & 0 & 1 \\
 & true & 2 & 3 \\
\hline
\end{tabular}

Idk what I did wrong tbh. I'm finding this multirow, multicolumn stuff a little confusing...

2 Answers2

5

Like this:

enter image description here

\documentclass{article}
\usepackage{multirow}

\begin{document}
\begin{tabular}{cc|cc}
            &           &   \multicolumn{2}{c}{A}   \\
\multicolumn{2}{c|}{\&} &   true    &   false       \\
    \hline
\multirow{2}{*}{B}      &   true    &   1   &    1  \\
                        &   false   &   2   &   3   
\end{tabular}
\end{document}

or this:

enter image description here

\documentclass{article}
\usepackage{multirow}

\begin{document}
\begin{tabular}{cc|cc}
\multicolumn{2}{c}{}    &   \multicolumn{2}{c}{A}   \\
\multicolumn{2}{c|}{\&} &   true    &   false       \\
    \hline
\multirow{2}{*}{B}      &   true    &   1   &   1   \\
            &   false   &   2       &   3           \\
\end{tabular}
\end{document}

or this?

enter image description here

\documentclass{article}
\usepackage{multirow}

\begin{document}
\begin{tabular}{|cc|cc|}
    \hline
\multicolumn{2}{|c|}{}  &   \multicolumn{2}{c|}{A}  \\
\multicolumn{2}{|c|}{\&}&   true    &   false       \\
    \hline
\multirow{2}{*}{B}      &   true    &   1   &   1   \\
            &   false   &   2       &   3           \\
    \hline
\end{tabular}
\end{document}

or finally (as described in your comment below):

enter image description here

\documentclass{article}
\usepackage{multirow}

\begin{document}
\begin{tabular}{|c|c|cc|}
    \hline
\multicolumn{2}{|c|}{}  &   \multicolumn{2}{c|}{A}  \\
    \cline{3-4}
\multicolumn{2}{|c|}{\&}&   true    &   false       \\
    \hline
\multirow{2}{*}{B}      &   true    &   1   &   1   \\
            &   false   &   2       &   3           \\
    \hline
\end{tabular}
\end{document}

to my taste, I would choose the first example ...

Zarko
  • 296,517
  • That last one is actually pretty nice, now that I think of it. – Osama Kawish Jun 18 '17 at 17:56
  • Tbh, I was going for something a bit more complicated and only wanted a box around the numbers, a line under the A, and a line next to the B as I showed. The entire table should also be boxed. – Osama Kawish Jun 18 '17 at 17:58
  • @OsamaKawish, I add one more example .... (sorry, your sketch was not very clear to me :-( ). – Zarko Jun 18 '17 at 18:55
0

Here is a way to do that table with {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{|c|c|cc|} \Hline \Block{2-2}{} & & \Block{1-2}{A} \ \Hline \Block{1-2}{&} & & true & false \ \Hline \Block{2-1}{B} & true & 1 & 1 \ & false & 2 & 3 \ \Hline \end{NiceTabular}

\end{document}

Output of the above code

F. Pantigny
  • 40,250