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.

I would like to combine the following two solutions provided in the question: How to draw arrows between parts of an equation to show the Math Distributive Property (Multiplication)?

  1. http://tex.stackexchange.com/a/35721/10898 and
  2. http://tex.stackexchange.com/a/61990/10898

The first is not reusable (at least I don't find a way to reuse several instances in one document since only one source can be defined.) The second is. What I am looking is to combine the \target command (this provides a north or south of the node in question, therefore directly targeting the character, like \target{x^2} as opposed to x\tikzmark{a}^2 or the sort.) and the second I can reuse in my example shown below:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node ({#1}) {};}
\tikzset{square arrow/.style={to path={-- ++(0,-.125) -| (\tikztotarget)}}}

\newcommand{\sn}[2]{\ensuremath{{#1}\times 10^{#2}}}
\begin{document}

    \begin{align*}
    \sn{23,900,00\tikzmark{b}0.\tikzmark{a}}{0} &= \sn{2,390,00\tikzmark{d}0.\tikzmark{c}0}{1}\\
                                                &= \sn{239,000}{2}\\
                        &= \sn{23,900}{3}\\
                        &= \sn{2,390}{4}\\
                        &= \sn{239}{5}\\
                        &= \sn{23.9}{6}\\
                        &= \sn{2.39}{7}
\tikz[overlay,remember picture] {\draw[->,square arrow] (a.south) to (b.south);}
\tikz[overlay,remember picture] {\draw[->,square arrow] (c.south) to (d.south);}
    \end{align*}
\end{document}

This yields:

enter image description here

Of course it is not a systematic (I welcome a systematic response.) way of doing it, but gets the job done. If the arrows could be set either as curves or as squares as they are, it is fine. If the arrows could be closer to the the targeted character that would be fine as well. What I want to achieve is something like the following:

enter image description here

share|improve this question
    
Please, don't use commas to separate thousands; use a thin space. In any case the comma (should you want to follow a non typographical convention) mustn't have a space after it. Use \num of siunitx to format them in a uniform way throughout your document: you can even customize it so that it uses commas for separating thousands (but don't do it). –  egreg Oct 9 '12 at 23:20
    
Since mathmode removes spaces I had to place a separator. –  azetina Oct 10 '12 at 0:20
    
Math mode doesn't remove \, which is the correct spacing; however \num is way better: it also takes care of the "exponent part". –  egreg Oct 10 '12 at 9:16
    
@egreg: \num seems to have an issue if there is a \tikzmark in the number itself. Probably fixable with some expansion related magic. –  Peter Grill Oct 11 '12 at 17:06

1 Answer 1

up vote 11 down vote accepted

It seems that you just need to tweak the points slightly to get the desired results which can be done using the tikz calc library. I have also defined a macro, \DrawArrow that has an optional first parameter to control the line style. Now you can produce both the square arrow, or curved arrows, with just changing the options to \DrawArrow:

enter image description here

Also shown is a version that uses \, to insert a small space for the thousands separator instead of a comma.

Notes:

  • I have defined two tweaks \PeriodAdjust and \DigitAdjust which are used to slightly move the two points, which is the simplest way to do this. An alternative is to let tikz compute the appropriate widths but not sure it would be worth the effort.
  • As per egreg's suggestion I used {,} for the commas so that additional space is not inserted.

Code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\usetikzlibrary{calc}

\newcommand{\PeriodAdjust}{0,0.60ex}%
\newcommand{\DigitAdjust}{-0.15em,0.60ex}%
\newcommand{\DrawArrow}[3][]{%
    \tikz[overlay,remember picture] {\draw[->,square arrow, thick, #1] 
        ($(#2.south)+(\DigitAdjust)$) to ($(#3.south)+(\PeriodAdjust)$);}
}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node ({#1}) {};}
\tikzset{square arrow/.style={to path={-- ++(0,-.125) -| (\tikztotarget)}}}

\newcommand{\sn}[2]{\ensuremath{{#1}\times 10^{#2}}}
\begin{document}
    \begin{align*}
    \sn{23{,}900{,}00\tikzmark{b}0.\tikzmark{a}}{0} &= \sn{2{,}390{,}00\tikzmark{d}0.\tikzmark{c}0}{1}\\
    \sn{23\,900\,00\tikzmark{f}0.\tikzmark{e}}{0} &= \sn{2\,390\,00\tikzmark{h}0.\tikzmark{g}0}{1}
    \end{align*}
    \DrawArrow[blue]{a}{b}
    \DrawArrow[red, out=-110, in=-70, distance=0.19cm, shorten >= -0.1ex]{c}{d}
    \DrawArrow[orange]{e}{f}
    \DrawArrow[cyan, out=-110, in=-70, distance=0.19cm, shorten >= -0.1ex]{g}{h}
\end{document}
share|improve this answer
    
The space after commas can be removed by writing {,} (of course not using commas but \, is better from a typographical point of view). –  egreg Oct 10 '12 at 9:18
    
Your code is missing the examples in your image. –  azetina Oct 13 '12 at 2:16
    
@azetina: Hmm, sorry, don't know how that happened... Corrected now. –  Peter Grill Oct 13 '12 at 8:26
    
@PeterGrill Very much appreciated thanks again. –  azetina Oct 13 '12 at 14:04

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.