-1

Any idea how can I draw this? I thought to use matices, but I have no idea how can I draw the circles around the index.

enter image description here

  • Only peripherally related: an alternate way of visually portraying matrix multiplication https://tex.stackexchange.com/questions/168035/matrix-decomposition-dimensions-diagram – Steven B. Segletes Aug 17 '21 at 16:18

2 Answers2

6

Perhaps tikzmark library from TikZ is what you need. With it you can create a node at any point in the document and then use it to draw the 'overlaying' diagram.

Something like this:

\documentclass {article}
\usepackage    {lipsum} % for dummy text
\usepackage    {tikz}
\usetikzlibrary{tikzmark}

\tikzset{every node/.style={minimum size=1.75ex}}

\begin{document} \lipsum[1]

[ A_{\tikzmarknode[red,draw,circle]{m1}{m}\times\tikzmarknode {n1}{n}} \quad\cdot\quad B_{\tikzmarknode {n2}{n}\times\tikzmarknode[blue,draw,circle]{p1}{p}} \quad=\quad AB_{\tikzmarknode[red,draw,circle]{m2}{m}\times\tikzmarknode[blue,draw,circle]{p2}{p}} ]

\begin{tikzpicture}[remember picture,overlay] \draw[red ,-latex] (m1.south) --++ (0,-1.5) -| (m2.south); \draw[blue ,-latex] (p1.south) --++ (0,-1) -| (p2.south); \draw[dashed] (n1.south) --++ (0,-1) -| (n2.south); \end{tikzpicture} \vspace{1.5cm} % we need space for the 'overlayed'` pciture

\lipsum[2] \end{document}

enter image description here

Edit1: As the picture is 'overlayed', you'll probably need to add some vertical space between it and the following text.

Edit 2: I removed the circles in the n1 and n2 nodes. There weren't such circles in the OP picture.

Juan Castaño
  • 28,426
4

A solution with pstricks: define the indices components as nodes of the relevant kind, and connect them with the \ncbar node connection.

\documentclass {article}

\usepackage{sansmath} \usepackage{pst-node}

\begin{document}

Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.

\sansmath

[ A_{\circlenode{ml}{m}\times\rnode{nA}{n}} \cdot B_{\rule{0pt} {2.5ex}\rnode{nB}{n}\times\circlenode{pl}{p}} = AB_{\circlenode{mr}{m}\times\circlenode{pr}{p}} \psset{arrowinset=0.12, linejoin=1, angle=-90, dash=3pt 2pt} \ncbar[armA=6mm]{->}{ml}{mr} \ncbar{->}{pl}{pr} \ncbar[linestyle=dashed, nodesep = 2pt]{-}{nA}{nB} ] \bigskip

Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.

\end{document}

enter image description here

Bernard
  • 271,350