Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Trying to apply the solution provided for the question How to draw arrows between parts of an equation to show the Math Distributive Property (Multiplication)? I have found a major problem as is shown in my example below:

\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}{Cerulean}\]

\begin{align*}
-(2x+5)&=(-\tikzmark{MarkA}1)(2x\tikzmark{MarkB}+5\tikzmark{MarkC})\DrawBox{OrangeRed}{Cerulean}\\
       &=(-1)(2x)+(-1)(5)\\
       &=-2x+(-5)\\
       &=-2x-5
\end{align*}

\end{document}

This gives:

enter image description here

To start with I don't like how the arrows leave and enter the node. I would like to able to control the height of the arc. Secondly, the arrow is not pointing correctly above the right node. I understand the command is not set to take the character and let it act as a node like in Jakes answer. This is a downfall.

Next, even when I tried Jakes method, there can only be one source but several targets. How can one define several sources. I like Peter Grill's answer since one can define several tikzmark's. This is very useful but in terms of appearance it is not the best. The color scheme I have chosen I wish to maintain standard but the other parameters I mentioned above I would like to be able to customize.

Hence, the arcs must be a suitable height (maybe let TikZ do the calculations) for this and that there can be several sources and targets without defining new \tikzmarks. Its somewhat a combination of both answers.

EDIT

I think that I am understanding the \tikzmark command but here is my major problem that can be avoided if the mathmode characters are selected as nodes as Jakes answer does.

This is the example where I see the most problem (probably its just my lack of understanding of TikZ and nodes.)

\documentclass[letterpaper]{article}
\usepackage{amsmath,amssymb}
\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]
    \node[xshift=0.85cm,yshift=0.65cm] (MarkExp) {\footnotesize Exponent};
    \node[xshift=-0.85cm,yshift=-0.35cm] (MarkBase) {\footnotesize Base};
    \draw[->,shorten >=6pt,out=180,in=90,#1] (MarkExp.west) to ([xshift=-2.5pt]MarktoExp.north);
    \draw[->,out=0,in=270,#2] (MarkBase.east) to ([xshift=2.5pt,yshift=2pt]MarktoBase.south);
  \end{tikzpicture}
}
\begin{document}
$\tikzmark{MarktoBase}2^3\tikzmark{MarktoExp}$\DrawBox{OrangeRed}{Cerulean}
\end{document}

enter image description here

I feel that in my solution above, I have forced the arrows to fit what I want even though it does the job. I sincerely believe there is a better method to achieve the same output as above.

share|improve this question
    
You can adjust the in, out angles to suit. Normally I provide an optional #1 so that those settings can be passed in as a parameter but in this case it appears that I did not do that. –  Peter Grill Jun 21 '12 at 22:50
    
Very true but how can you then modify your code so that the arrow actually points to the target similar to Jakes answer. How can I get a semi-circle for the arc? Or at least control the height of the arc? –  azetina Jun 21 '12 at 23:01
add comment

1 Answer

up vote 9 down vote accepted

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.

enter image description here

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}
share|improve this answer
    
See my updated question. –  azetina Jun 23 '12 at 18:22
    
@azetina: Regarding your updated question: I recommend you use em units to apply the horizontal shift as opposed to cm, then the shift is relative to the font size. Other that that, your solution seems good. One thing you have to consider is if you want to be doing a \Draw... type of macro for every instance? I would recommend you pass in parameters (as I did in this answer) to the macro to do the tweaks, then the same macro can be used more than once. Similarly, you can pass in the node names to the \Draw... macros that you can choose the node names on a per application basis. –  Peter Grill Jun 23 '12 at 18:49
    
I will do my homework and try my best to adapt the most suitable solution but if not I will definitely get back to you for clarifications. :-) (PS. Still learning) –  azetina Jun 24 '12 at 2:32
    
@azetina: Ok. I too am still learning. –  Peter Grill Jun 24 '12 at 2:54
    
At least that gives me some hope in my moments of desperation and unsuccessful attempts in mastering LaTeX hacks and TikZ commands. (sigh!) –  azetina Jun 24 '12 at 2:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.