# Matrix product in Latex

I would be immensely happy if I could draw this neat (even if absolutely unoriginal) way to present the matrix product in LaTeX :

If possible, I would like a code quite simple, that doesn't use tikz, and rather rely on the array environment.

Is there any way to do so?

A first approach with nicematrix.

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

$\begin{NiceArray} [xdots/line-style={solid,<->},cell-space-limits=10pt] {ccccccw{c}{5mm}} & \hspace*{10mm} & \hspace*{10mm} & & \Hdotsfor[shorten=-\arraycolsep]{1}^r & \Hdotsfor[shorten=-\arraycolsep]{1}^{n-r}\\ & & & & A' & B' & \Vdotsfor[shorten=0pt]{1}^{q}\\ & & & & C' & D' & \Vdotsfor[shorten=0pt]{1}^{n-q}\\ & \Hdotsfor[shorten=-\arraycolsep]{1}^q & \Hdotsfor[shorten=-\arraycolsep]{1}^{n-q}\\ & A & B & & AA'+BC' & AB'+BD' & \Vdotsfor[shorten=0pt]{1}^{p}\\ & C & D & & CA'+DC' & CB'+DD' & \Vdotsfor[shorten=0pt]{1}^{n-p}\\ & & & & \Hdotsfor[shorten=-\arraycolsep]{1}^{r} & \Hdotsfor[shorten=-\arraycolsep]{1}^{n-r} \\ \CodeAfter \SubMatrix({2-5}{3-6})[hvlines] \SubMatrix({5-5}{6-6})[hvlines] \SubMatrix({5-2}{6-3})[hvlines] \end{NiceArray}$

\end{document}


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

• Excellent. But is it possible to join the arrows where is it necessary? Aug 5, 2021 at 12:23
• @Sebastiano: I've modified my answer. Aug 5, 2021 at 12:33
• But I had already voted for it previously :-) Aug 5, 2021 at 12:34
• This is wonderful, thank you very much! Aug 5, 2021 at 14:00