0

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

Neato matrix product

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?

0

1 Answer 1

3

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

Output of the above code

4
  • Excellent. But is it possible to join the arrows where is it necessary?
    – Sebastiano
    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 :-)
    – Sebastiano
    Aug 5, 2021 at 12:34
  • This is wonderful, thank you very much!
    – fbatch
    Aug 5, 2021 at 14:00

Your Answer

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.