在方程上画连接箭头

在方程上画连接箭头

我想画出如下图所示的箭头,抱歉图像质量较差。

在此处输入图片描述

公式如下:

\lambda_1(2,1,-1) + \lambda_2 (1,1,1) = (4,1,-5)

关于如何实现这一点有什么建议吗?

编辑: 尝试在这里搭建这段代码但失败了,没有任何结果出现:

https://tex.stackexchange.com/a/168978/107417

在帖子中添加了包和命令,并将我的方程式代码更改为

\begin{equation*}
\source{\lambda_1}(2,1,-1) + \source{\lambda_2} (\target{1},1,1) = (\target{4},1,-5)
\end{equation*}

编辑2:

\documentclass[11pt]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}

\usepackage{tikz,pgfplots}

\newcounter{source}
\newcommand\source[1]{%
    \tikz[remember picture,baseline,inner sep=0pt] {%
        \node [name=source-\thesource,anchor=base]{$#1$};
    }%
    \setcounter{target}{0}
    \stepcounter{source}
}

\newcounter{target}
\newcommand\target[1]{%
    \tikz[remember picture,baseline,inner xsep=0pt] {%
        \node [name=target-\thetarget,anchor=base]{$#1$};
    }%
    \setcounter{source}{0}
    \stepcounter{target}%
}
\newcommand\drawarrows{
    \tikz[remember picture, overlay, bend left=45, -latex] {
    \foreach \j [evaluate=\j as \m using int(\j)] in {1,...,\thesource}{
        \foreach \i [evaluate=\i as \n using int(\i-1)] in {1,...,\thetarget} {
            \draw [red](source-0.north) to (target-\n.north) ;
              \node [red] at ([xshift=-5mm]target-\n.north) [above=2mm] {\i};
          }

    }
}

 \tikz[remember picture, overlay, bend left=-45, -latex] {
    \foreach \j [evaluate=\j as \m using int(\j)] in {1,...,\thesource}{
        \foreach \i [evaluate=\i as \n using int(\i-1)] in {1,...,\thetarget} {
            \draw [blue](source-1.south) to (target-\n.south)  ;
      \pgfmathsetmacro{\ii}{\i+2)};
         \node [blue] at ([xshift=-2mm]target-\n.south) [below=2mm] {\pgfmathprintnumber \ii};
    }
}
}}

\begin{document}

\begin{equation*}
\source{\lambda_1}(2,1,-1) + \source{\lambda_2} (\target{1},1,1) = (\target{4},1,-5)
\end{equation*}

\end{document}

答案1

看看以下解决方案是否令人满意:

\documentclass[12pt,
               tikz,
               preview,
               border=3mm]{standalone}

\usetikzlibrary{arrows.meta, bending, chains}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\begin{document}
\[
    \begin{tikzpicture}[
node distance = 0pt,
  start chain = A going right,
    inner sep = 0pt,
    outer sep = 0pt,
every node/.style = {on chain=A}                       
                        ]
% equation
\node{$\lambda_1$}; % A-1
\node{$($};         % A-2
\node{$2,1$};       % A-3
\node{$,-1) + $};
\node{$\lambda_2$}; % A-5
\node{$($};         % A-6
\node{$1,1$};       % A-7
\node{$,1)=$(};
\node{$4$};        % A-9
\node{$,1,-5)$};
% lines
    \begin{scope}[
        every path/.append style = {-{Stealth[flex]}, draw=gray, very thick},
                  ]
% arrows are arranged from bottom (left to right) to top (right to left)
\draw (A-1.north) to [out=75,in=120] (A-3.north);% 1, bottom
\draw (A-5.north) to [out=75,in=105] (A-7.north);% 2, bottom
\draw (A-5.north) to [out=60,in=120] coordinate[pos=0.3] (b) % <-- coordinate for join point
      (A-9.north);% 2, bottom
\draw (A-1.north) to [out=60,in=120] (b);% 1, top
    \end{scope}
    \end{tikzpicture}
\]
\end{document}

在此处输入图片描述

附录: 具有更多彩色(开始为红色)箭头的解决方案(正如 Alenanno 在他的评论中所建议的那样):

在此处输入图片描述

对于上图,具有起始范围的行是:

\begin{scope}[
    every path/.append style = {-{Stealth[flex]}, draw=red, very thick},
              ]

如果有人愿意,也可以通过简单地将颜色添加到特定节点来更改方程部分的颜色:-)

答案2

有了tikzmark库,这可以很容易:

\documentclass[11pt]{article}
\usepackage{amsmath,tikz}
\usetikzlibrary{tikzmark}
\begin{document}

\[
\lambda\tikzmark{0}_1(2,1,-1) + \lambda\tikzmark{1}_2 (\tikzmark{00}1,1,1) = (\tikzmark{11}4,1,-5)
\]

\begin{tikzpicture}[remember picture, overlay, bend left=45, -latex, blue]
  \draw ([yshift=2ex]pic cs:0) to ([yshift=2ex]pic cs:00);
  \draw ([yshift=2ex]pic cs:1) to ([yshift=2ex]pic cs:11);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容