# 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 '14 at 10:46

Here's another proposal based on Gonzalo's answer to this question.
The following code gives you four new commands to be able to diagonally cross out and point to (cancel to) from all four possible directions:

• canceltoSwNe{From}{To}: Cross out diagonally from South-West to North-East
(Bottom-Left to Top-Right)
• canceltoNeSw{From}{To}: Cross out diagonally from North-East to South-West
(Top-Right to Bottom-Left)
• canceltoSeNw{From}{To}: Cross out diagonally from South-East to North-West
(Bottom-Right to Top-Left)
• canceltoNwSe{From}{To}: Cross out diagonally from North-West to South-East
(Top-Left to Bottom-Right)

Some remarks:

• The order of the two arguments is inverse in comparison to the cancelto command from the cancel package, but I find it more logical this way.
• The bounding box differs from the cancel package, see the background color and the fraction examples. This might or might not suit your needs.
The presented cancelto's accept text or math as an argument and can be used in text or in math mode.
The presented cancelto's can be nested, contrary to the ones from the cancelto package.
• As can be seen in the fraction example, the font resizing is not working properly and I couldn't quickly find an easy solution for this problem.
Suggestions are more than welcome!

Here's the code with a couple of examples:

\documentclass{article}

\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.3}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}

\usepackage{cancel}

% ==================================================================================

\usepackage{relsize}

\newcommand\canceltoSwNe[2]{%
\begin{tikzpicture}[baseline = (B.base)]
\node[anchor = center, inner sep = 0pt] (B) {#1};
\draw[arrows = {}-{latex}]%
($(B.south west)+(-1pt, -1pt)$) -- ($(B.north east)+(+4pt, +1pt)$)%
node [anchor = south west, xshift = +1pt, yshift = -1pt,%
inner sep = 0pt]%
{\smaller\smaller{#2}};
\end{tikzpicture}%
}

\newcommand\canceltoNeSw[2]{%
\begin{tikzpicture}[baseline = (B.base)]
\node[anchor = center, inner sep = 0pt] (B) {#1};
\draw[arrows = {}-{latex}]%
($(B.north east)+(+1pt, +1pt)$) -- ($(B.south west)+(-4pt, -1pt)$)%
node [anchor = north east, xshift = -1pt, yshift = +1pt,%
inner sep = 0pt]%
{\smaller\smaller{#2}};
\end{tikzpicture}%
}

\newcommand\canceltoSeNw[2]{%
\begin{tikzpicture}[baseline = (B.base)]
\node[anchor = center, inner sep = 0pt] (B) {#1};
\draw[arrows = {}-{latex}]%
($(B.south east)+(+1pt, -1pt)$) -- ($(B.north west)+(-4pt, +1pt)$)%
node [anchor = south east, xshift = -1pt, yshift = -1pt,%
inner sep = 0pt]%
{\smaller\smaller{#2}};
\end{tikzpicture}%
}

\newcommand\canceltoNwSe[2]{%
\begin{tikzpicture}[baseline = (B.base)]
\node[anchor = center, inner sep = 0pt] (B) {#1};
\draw[arrows = {}-{latex}]%
($(B.north west)+(-1pt, +1pt)$) -- ($(B.south east)+(+4pt, -1pt)$)%
node [anchor = north west, xshift = +1pt, yshift = +1pt,%
inner sep = 0pt]%
{\smaller\smaller{#2}};
\end{tikzpicture}%
}

% ==================================================================================

\begin{document}

\noindent%
%
%
Baseline\:%
\colorbox{yellow!30!white}{%
\canceltoSwNe{Text to cancel}{Text to write}
}\hspace*{5mm}\colorbox{blue!30!white}{%
$\cancelto{\text{Text to write}}{\text{Text to cancel}}$
}\\
%
Baseline\:%
\colorbox{yellow!30!white}{%
\canceltoSwNe{Text to cancel}{$x^{2}_{z}$}
}\hspace*{5mm}\colorbox{blue!30!white}{%
$\cancelto{x^{2}_{z}}{\text{Text to cancel}}$
}\hspace*{25mm}%
%
\colorbox{yellow!30!white}{%
\canceltoSwNe{$a + 3 \cdot \frac{x}{\alpha}$}{$123$}
}\hspace*{5mm}\colorbox{blue!30!white}{%
$\cancelto{123}{a + 3 \cdot \frac{x}{\alpha}}$
}\\[5mm]
%
%
Baseline\:%
\colorbox{yellow!30!white}{%
\canceltoSwNe{$a + 3 \cdot \frac{x}{\alpha}$}{$b - 4 \cdot \frac{\beta}{z}$}
}\hspace*{5mm}\colorbox{blue!30!white}{%
$\cancelto{b - 4 \cdot \frac{\beta}{z}}{a + 3 \cdot \frac{x}{\alpha}}$
}\\[5mm]
%
%
Baseline\:%
\colorbox{yellow!30!white}{%
\canceltoSwNe{$xyz$}{$xyz$}
}\hspace*{5mm}\colorbox{blue!30!white}{%
$\cancelto{xyz}{xyz}$
}\hspace*{15mm}%
%
\colorbox{yellow!30!white}{%
\canceltoSwNe{$xyz$}{\canceltoSwNe{$xyz$}{$xyz$}}
}\hspace*{5mm}\colorbox{blue!30!white}{%
$\cancelto{xyz}{\cancelto{xyz}{xyz}}$
}\hspace*{15mm}%
%
\colorbox{yellow!30!white}{%
\canceltoSwNe{$xyz$}{\canceltoSwNe{$xyz$}{\canceltoSwNe{$xyz$}{$xyz$}}}
}\hspace*{5mm}\colorbox{blue!30!white}{%
$\cancelto{xyz}{\cancelto{xyz}{\cancelto{xyz}{xyz}}}$
}\\[5mm]
%
%
Baseline\:%
\colorbox{yellow!30!white}{%
$\frac{1}{\canceltoSwNe% {$x + y + z^{2} - \lim\limits_{a \rightarrow \infty} \frac{1}{a}$}% {A very, very long text}}$
}\hspace*{5mm}\colorbox{blue!30!white}{%
$\frac{1}{\cancelto{\text{A very, very long text}}% {x + y + z^{2} - \lim\limits_{a \rightarrow \infty} \frac{1}{a}}}$
}\\[10mm]

\noindent%
%
%
Baseline\:%
\colorbox{yellow!30!white}{%
\canceltoSwNe{$a + 3 \cdot \frac{x}{\alpha}$}{$b - 4 \cdot \frac{\beta}{z}$}
}\hspace*{5mm}\colorbox{yellow!30!white}{%
\canceltoNeSw{$a + 3 \cdot \frac{x}{\alpha}$}{$b - 4 \cdot \frac{\beta}{z}$}
}\hspace*{5mm}\colorbox{yellow!30!white}{%
\canceltoSeNw{$a + 3 \cdot \frac{x}{\alpha}$}{$b - 4 \cdot \frac{\beta}{z}$}
}\hspace*{5mm}\colorbox{yellow!30!white}{%
\canceltoNwSe{$a + 3 \cdot \frac{x}{\alpha}$}{$b - 4 \cdot \frac{\beta}{z}$}
}

\end{document}

% ==================================================================================


Here's the result:

-

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_{}}$$


or

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

-