1

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!

Cross table

New contributor
Fin is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • Welcome to TeX SX! You don't need a hammersledge like tikz for that. The blkarray package can do it. – Bernard May 4 at 14:26
1

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}

image of table

1

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).

Output of the above code

Your Answer

Fin is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.