3

I try to reproduce the figure but I am unable to adjust the arrows between the nodes of the matrices

enter image description here

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning,fit}
\tikzset{arrow style mul/.style={circle,midway,fill=white}}

\begin{document}

\begin{tikzpicture} [thick,baseline=(A.center),>=stealth, every left delimiter/.append style={name=rd},thick]

\matrix [matrix of math nodes,left delimiter=(,right delimiter=)]                    
       (A) at (0,0) { 
                     |[red]| a   &  |[blue]|b    \\
                      c          &          d    \\
};

\matrix [matrix of math nodes,left delimiter=(,right delimiter=)]
        (P) at (4cm,0) { 
                        |[green]| ae + bf \\
                         ce + df \\
};

\matrix [matrix of math nodes,left delimiter=(,right delimiter=)] (B) at (4cm,2cm) { |[red]| e \ |[blue]| f \ };

\draw[red,->](A.north -|A-1-1) -- node[arrow style mul] (x) {$\times$} (rd.west|-B-1-1.center); \draw[blue,->](A.north -|A-1-2) -- node[arrow style mul] (x) {$\times$} (rd.west|-B-2-1.center);

\end{tikzpicture}

\end{document}

enter image description here

Fabrice
  • 3,636
  • 1
  • 21
  • 29

2 Answers2

4

enter image description here

    \documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning,fit}
\tikzset{arrow style mul/.style={circle,yshift=4pt,}}

\begin{document}

\begin{tikzpicture} [thick,baseline=(A.center),>=stealth, every left delimiter/.append style={name=rd},thick]

\matrix [matrix of math nodes,left delimiter=(,right delimiter=)]                    
       (A) at (0,0) { 
                     |[red]| a   &  |[blue]|b    \\
                      c          &          d    \\
};

\matrix [matrix of math nodes,left delimiter=(,right delimiter=)]
        (P) at (4cm,0) { 
                        |[green]| ae + bf \\
                         ce + df \\
};

\matrix [matrix of math nodes,left delimiter=(,right delimiter=)] (B) at (4cm,2cm) { |[red]| e \ |[blue]| f \ };

\draw[red,->](A.north -|A-1-1) -- node[arrow style mul] (x1) {$\times$} (rd.west|-B-1-1.center); \draw[blue,->](A.north -|A-1-2) -- node[arrow style mul] (x2) {$\times$} (rd.west|-B-2-1.center); \coordinate(a)at($(x2)+(0,-12pt)$); \drawgreen,->node[left]{+}-|(P.north); \end{tikzpicture}

\end{document}

js bibra
  • 21,280
4

I'm adapting my answer to "How to add arrow in equations and matrix?" to your example; check it out for some explanations. Basically, you have to

  • typeset the mathematical part (the matrices)

  • wrap all parts that you want to reference in the drawing commands into a \tikznode command, which assigns a name to it and stores the size of the box as well as its position

  • add a tikzpicture environment starting with

    \begin{tikzpicture}[remember picture,overlay,...]
    

    that contains the drawing commands.

  • run LaTeX twice to get the positions right.

enter image description here

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\newcommand\tikznode[3][]{
  \tikz[remember picture,baseline=(#2.base)]
    \node[minimum size=0pt,inner sep=0pt,#1](#2){#3};%
}
\begin{document}

( \begin{array}{l@{\qquad}l} & \begin{pmatrix} \tikznode[red ]{e}{$e$} \ \tikznode[blue]{f}{$f$} \end{pmatrix} \[5ex] \begin{pmatrix} \tikznode[red]{a}{$a$} & \tikznode[blue]{b}{$b$} \ c & d \end{pmatrix} & \begin{pmatrix} \tikznode[green]{ae+bf}{$ae+bf$} \ ce + df \end{pmatrix}
\end{array} ) \begin{tikzpicture}[ remember picture, overlay, rounded corners, >=stealth, thick ] \draw[->,red ,shorten <=2pt,shorten >=6pt] (a) to[out=80,in=-180] node[above]{$\times$} (e); \draw[->,blue ,shorten <=2pt,shorten >=6pt] (b) to[out=80,in=-180] node[above,pos=0.4]{$\times$} (f); \draw[<-,green,shorten <=2pt,shorten >=6pt] (ae+bf) |- ++(-1.3,0.5) node{$+$}; \end{tikzpicture} \end{document}

gernot
  • 49,614
  • Thank you very much but the compilation returns an error ! LaTeX Error: Bad math environment delimiter. – Fabrice Jan 18 '21 at 16:52
  • @Fabrice Which document yields this error? If I copy my code into a new file and run latex, I get no error. If you get an error with my code, it's maybe necessary to update your LaTeX system. If your own code gives this error, it is difficult to guess the reason without seeing the code. – gernot Jan 18 '21 at 17:24
  • Your code but with this \documentclass[border=5pt]{standalone} because I have to insert the figure in my course. – Fabrice Jan 18 '21 at 17:42
  • Replace \[ ... \] by \( ... \). standalone does not like environments and commands that rely on the text width; alternatively, you can use the varwidth option of standalone. I have edited my code. – gernot Jan 18 '21 at 18:15