This already has the structure built in for you to provide other options to control the lines that are drawn. You can adjust the
out=
to control the angle at the start of the arrow,
in=
to control the angle at the end of the arrow,
distance=
to control the height of the arrow,
- and the two
shorten
to adjust how close the start and end are to the particular node.
There are probably other options, that should be in the PGF manual related to the syntax of using to
instead of --
for line drawing.
Notes:
- I also moved the position of the in:
2\tikzmark{MarkB}x
so that the arrow points to the center of the 2x
term.
Code:
\documentclass{article}
\usepackage{amsmath}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,shapes}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\DrawBox}[2]{%
\begin{tikzpicture}[overlay,remember picture]
\draw[->,shorten >=5pt,shorten <=5pt,out=70,in=130,distance=0.5cm,#1] (MarkA.north) to (MarkC.north);
\draw[->,shorten >=5pt,shorten <=5pt,out=50,in=140,distance=0.3cm,#2] (MarkA.north) to (MarkB.north);
\end{tikzpicture}
}
\begin{document}
\[\tikzmark{MarkA}a(b\tikzmark{MarkB}+c\tikzmark{MarkC})=ab+ac \DrawBox{OrangeRed,distance=0.75cm,in=110,shorten >=3pt}{Cerulean,out=60,in=110,distance=0.5cm}\]
\begin{align*}
-(2x+5)&=(-\tikzmark{MarkA}1)(2\tikzmark{MarkB}x+5\tikzmark{MarkC})\DrawBox{OrangeRed,distance=0.75cm}{Cerulean,out=60,in=110,distance=0.5cm}\\
&=(-1)(2x)+(-1)(5)\\
&=-2x+(-5)\\
&=-2x-5
\end{align*}
\end{document}
The following code maybe a starting point for you:
\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\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 sep=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) coordinate (UP);
}
\node [red] at (UP) [above] {1};
}
}
\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) coordinate (DOWN) ;
}
\node [blue] at (DOWN) [below] {2};
}
}
}
\begin{document}
\begin{equation}
(\source{a}+\source{4})(\target{b}+\target{3})=\mbox{\drawarrows}
\end{equation}
\end{document}
Output:
Update: Labeling each arrow:
\documentclass[]{article}
\usepackage[utf8]{inputenc}
\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{a}+\source{4})(\target{b}+\target{3})=\mbox{\drawarrows}
\end{equation}
\end{document}
and the output:
Best Answer
The following uses
pst-node
from thepstricks
bundle. So, you need to compile it with eitherlatex
->dvips
->ps2pdf
, orxelatex
:\psDefBoxNodes{<node>}{<stuff>}
declares a special node<node>
for<stuff>
. Subsequently one can refer to the bounding box location of the node using character combinations. In the above example,<node>:tC
refers to thet
opC
enter of<node>
.