# How to do left and top descriptions of a cross table?

Is it possible to make a table as this in a  \begin{tabular}...\end{tabular} kind of thing? I didn't even really know what to search for, so I didn't find anything on the internet. And a solution without using tikz would be greatly appreciated as I struggle to understand what's going on in tikz.

Thanks for any help!

• Welcome to TeX SX! You don't need a hammersledge like tikz for that. The blkarray package can do it. May 4, 2021 at 14:26

Just use multirow.

\documentclass[12pt,a4paper]{article}
\usepackage{multirow}
\begin{document}

\begin{table}[ht]
\caption{Multi-row table}
\begin{center}
\begin{tabular}{c|c|c|c|c}
\multicolumn{2}{c}{}&\multicolumn{2}{c}{\textbf{Y}}&\\\cline{3-4}
\multicolumn{2}{c|}{}&$b_{1}$&$b_{2}$&$\sum$\\\cline{2-4}
\multirow{2}{*}{\textbf{X}} & $a_1$ & & 12 & 34\\\cline{2-4}
& $a_2$ & & & 63\\\cline{2-4}
\multicolumn{1}{c}{}& \multicolumn{1}{c}{$\sum$} & \multicolumn{1}{c}{55} & \multicolumn{1}{c}{42} & \multicolumn{1}{c}{97}\\
\end{tabular}
\end{center}
\label{tab:XY}
\end{table}

\end{document}


With {NiceMatrix} of the package nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

$\begin{NiceMatrix}[first-row,last-row=4,first-col,last-col=4,hvlines,corners=NW] & & \Block{1-2}{Y} \\ & & b_1 & b_2 & \sum \\ \Block{2-1}{X} & a_1 & & 12 & 34 \\ & a_2 & & & 63 \\ & \sum & 55 & 42 & 97 \\ \end{NiceMatrix}$

\end{document}


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