10

I'm trying to add arrows to math expressions (especially within limits) to note that there's a value assigned to certain term when solving a limit. I've come across the cancel package and its command \cancelto{}{} but I have 2 problems with it: 1. It strikes through the term like it's canceling it (obviously) 2. It only goes upwards (right upwards but the right part doesn't bother me), whereas I might need it to go downwards when I'm showing a tendency in the denominator of a fraction.

Searching here I found a custom command that sort of does the job (I modified it a little), and got it going, sadly it works half the time. The other half it just disarranges all the baselines of the other elements in te equation. I'll leave you the code of the commands (which again, is not mine to credit for) and an error that I'm having in hope someone can help me. I'm still learning Tikz so I'm unable to solve it myself although I suspect that there lies the answer to my problem.

The code modified by me:

\usetikzlibrary{calc}

\newcommand*\canc[1]{%
  \mathchoice
    {\scriptstyle#1}
    {\scriptstyle#1}
    {\scriptscriptstyle#1}
    {\scriptscriptstyle#1}
}

\newcommand*\dtendto[2][0]{%
  \kern9pt%
  \begin{tikzpicture}[baseline=(current bounding box.center).anchor=east]
    \node[anchor=east] (a) {$#2$};
    \draw[->, color = red] ($(a.south)$) -- ($(a.south)-(-4pt,8pt)$) node
    at ($(a.south)-(-8pt,12pt)$) {$\canc{#1}$};
\end{tikzpicture}
}


\newcommand*\utendto[2][0]{%
  \kern9pt%
  \begin{tikzpicture}[baseline=(current bounding box.south).anchor=east]
    \node[anchor=east] (a) {$#2$};
    \draw[->, color = red] ($(a.north)$) -- ($(a.north)+(4pt,8pt)$) node
    at ($(a.north)+(8pt,12pt)$) {$\canc{#1}$};
\end{tikzpicture}
}

The part where I'm having trouble (I've earlier parts in which this worked but surely a correct code would still work on those).

\lim_{x\to\infty} \frac{\bcancel{x^5}\cdot(\utendto[2]{2}
-\utendto[0]{\frac{3}{x^2}} +
\utendto[0]{\frac{2}{x^4}})}{\bcancel{x^5}\cdot\left(4 + \frac{5}{x}
-\frac{100}{x^5}\right)}

And a snapshot of how it displays, notice that what I'd like to happen is that the arrows are added on top, as if the equation didn't even know they are there. Now it seems it is responding to what I add trying to center the + and - signs (even the parenthesis if I use \left( and \right) ) distorting a normal look.

ErrorImage

And here's a photoshopped version of what i'd like it to look like: ExpectedImage

Basically what I want is the equation to ignore the arrows and to be typeset just as if they weren't there (except of course for the vertical spacing not to be superposed with other lines or equations on top or bottom).

I've managed to create a new command called \dtendto[]{} that does the same except that the arrow goes southeast instead of northeast but I think the solution is the same for both so as not to make the post longer I ommited it.

Thanks in advance,

  • Inside of the node, the \mathchoice macro will always detect text-style. – Qrrbrbirlbel Dec 22 '13 at 21:49
  • adding inner sep=0pt,outer sep=0pt to the nodes should help – clemens Dec 22 '13 at 22:46
3

Remarks

I added inner xsep=0pt and outer sep=0pt, also I limited the bounding box.

In my edit, I got rid of the calc library, as it isn't really needed. Furthermore I set inner sep=0pt of the nodes and shorten <=.3333em of the arrows, to preserve spacing between digit and arrow, whilst cancelling extra space below the digit.

I repleaced all values by scalable units (ex and em).

Also, you don't need the \canc macro, as it will always default to \scriptstyle in your implementation.

Implementation

\documentclass{article}
\pagestyle{empty}
\usepackage{tikz,cancel}
\renewcommand{\CancelColor}{\color{red}}

\newcommand*\dtendto[2][0]{%
    \begin{tikzpicture}[baseline=(a.base),every node/.style={inner sep=0pt,outer sep=0pt}]
        \node (a) {$#2$};
        \path[red] (a.south) node (b) at +(0.5em,-3ex) {$\scriptstyle #1$};
        \draw[->,red,shorten <=.3333em,shorten >=.3333em] (a) -- (b);
        \pgfresetboundingbox
        \path[use as bounding box] (a.north west) rectangle (a.south east |- b.south);
    \end{tikzpicture}
}


\newcommand*\utendto[2][0]{%
    \begin{tikzpicture}[baseline=(a.base),every node/.style={inner sep=0pt,outer sep=0pt}]
        \node (a) {$#2$};
        \path[red] (a.north) node (b) at +(0.5em,3ex) {$\scriptstyle #1$};
        \draw[->,red,shorten <=.3333em,shorten >=.3333em] (a) -- (b);
        \pgfresetboundingbox
        \path[use as bounding box] (a.south west) rectangle (a.north east |- b.north);
    \end{tikzpicture}
}
\begin{document}
\fbox{
$\displaystyle
    \lim_{x\to\infty} \frac{\bcancel{x^5}\cdot(\utendto[2]{2}
    -\utendto[0]{\frac{3}{x^2}} +
    \utendto[0]{\frac{2}{x^4}})}{\bcancel{x^5}\cdot\left(\dtendto[4]{4} + \frac{5}{x}
    -\frac{100}{x^5}\right)}
$
}
\end{document}

Output

In the real output the bounding boxes won't be highlighted. I just colored them green for illustration purposes.

enter image description here

  • Henri! Thanks a lot!! It did the job splendidly!! Just one tiny thing: when using an align environment and being this equation in an inner line of the environment the arrow overlap with the upper line. I could (and will) correct this leaving empty lines above (and below), but just for the sake of it. Is there a way to expand the box? So as to take more vertical space for that line? Nevertheless, what you did is (at least for me), genius and I thank you very much for it. – Ewajs Dec 25 '13 at 1:58
  • @Ewajs See my updated answer. – Henri Menke Dec 25 '13 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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