# cancel package downward arrow

Let's say that I want to cancel the denominator of a fraction and also assign him a value. Something like that \cancel{2}\cdot\dfrac{9}{\cancelto{2}{4}}. The problem here is that the fraction doesn't look good at all after that. So I need a cancelto command that creates a downward arrow. Is there any way to do it?

-

With the help of TikZ you can define a command to cancel an expression using a downward arrow:

\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage{cancel}
\usepackage{tikz}
\usetikzlibrary{calc}

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

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

\begin{document}

$\Dcancelto[1]{7}$

$\frac{1}{\Dcancelto[2]{4}}$

$\frac{89}{\Dcancelto[0]{4367}}$

$\cancel{2}\cdot\dfrac{9}{\Dcancelto[2]{4}}$

\end{document}


Here's the result:

-
thanks for the great answer, I´ve also modified {#2} to {$#2$} in \node[anchor=east,inner sep=2pt] (a) {#2}; to work properly with math expressions like fractions –  escalator Apr 11 at 10:46
To change the arrow direction you need to rewrite most of the internals of the cancel package. I would NOT recommend that, because it is very complicated code. May be you can try some other options such as
$$\bcancel{2}\cdot\dfrac{9}{{\bcancel{4}}^2_{}}$$

$$\cancel{2}\cdot\dfrac{9}{{\cancel{4}\rule{0pt}{2.ex}}^{\;2}_{}}$$