6

I would like to draw arrows like I show in the image below, sorry for the bad quality of the image.

enter image description here

Here is the equation:

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

Any tips on how this could be accomplished?

EDIT: Tried to scaffold this bit of code here but failed miserably without any result showing up:

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

added the packages and commands in the post and changed my equation-code to

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

EDIT 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}
Clone
  • 533
  • 2
    Welcome to TeX.SE! Your question is close related to http://tex.stackexchange.com/questions/328667/arrows-over-under-and-around-math-text and duplicate to http://tex.stackexchange.com/questions/35717/how-to-draw-arrows-between-parts-of-an-equation-to-show-the-math-distributive-pr and http://tex.stackexchange.com/questions/168972/draw-arrows-to-show-multiplication-pattern-distributive-property – Zarko Sep 09 '16 at 16:16
  • The link you provide contain slution to your problem. Try replaced equation used there with your and show complete example code, which we can compile (starting with \docummentclass{...} used packages relevant to your problem, \begin{document} your code and ending with \end{document} – Zarko Sep 09 '16 at 16:50
  • @Zarko editing post – Clone Sep 09 '16 at 19:27

2 Answers2

4

With tikzmark library, this can be easy:

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

enter image description here

AboAmmar
  • 46,352
  • 4
  • 58
  • 127
3

See, if the following solution is satisfactory:

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

enter image description here

Addendum: solution with more colorful (for start red) arrows (as Alenanno suggest in his comment):

enter image description here

for above image the line with start scope is:

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

if anyone wish, can also change the equation part color by simple add the collor to particular node :-)

Zarko
  • 296,517
  • Why gray? More color! :D – Alenanno Sep 09 '16 at 22:30
  • Do you mean that more colorful answer will attract more attentions for up-voters? :-) which is than right one? well, fort star I will add one image with red arrows :-) – Zarko Sep 09 '16 at 22:38
  • I was just saying, colors are beautiful. :P – Alenanno Sep 09 '16 at 22:51
  • Is it possible to like remove one arrowhead? The one which is connecting. The thing you did is like magic to me. – Clone Sep 12 '16 at 19:39
  • 1
    yes, it is posible. just delete code for this arrow. I will add comments to each arrow, that you can easy identify them. – Zarko Sep 12 '16 at 19:41