调整两个矩阵节点之间的箭头

调整两个矩阵节点之间的箭头

我尝试重现该图,但无法调整矩阵节点之间的箭头

在此处输入图片描述

\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}

在此处输入图片描述

答案1

我正在适应我对“如何在方程和矩阵中添加箭头?”的回答您的示例;请查看一些解释。基本上,您必须

  • 排版数学部分(矩阵)

  • 将您想要在绘图命令中引用的所有部分包装到一个\tikznode命令中,该命令为其分配一个名称并存储框的大小及其位置

  • 添加tikzpicture以开头的环境

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

    包含绘图命令。

  • 运行 LaTeX 两次以获得正确的位置。

在此处输入图片描述

\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}

答案2

在此处输入图片描述

    \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)$);
\draw[green,->](a)node[left]{+}-|(P.north);
\end{tikzpicture}

\end{document}

相关内容