11

The following solution to the question where soome maths text is to be cancelled out makes use of the cancel package. There the macro \cancelto produces an arrow from bottom left to top right. It also gives a macro called \bcancel which gives a strike out from top left to bottom right.

Is it possible to have a macro that combines these two together, something of the form \bcancelto: an arrow from top-left to bottom-right.

Here is a MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage[makeroom]{cancel}

\begin{document}
\noindent
\verb|\cancel{5y}|:
\[ x+\cancel{5y}=0\]
\verb|\bcancel{5y}|:
\[ x+\bcancel{5y}=0\]
\verb|\xcancel{5y}|:
\[ x+\xcancel{5y}=0\]
\verb|\cancelto{\infty}{5y}|:
\[ x+\cancelto{\infty}{5y}=0\]

\end{document}
2
  • Is \xcancel{} what you want?
    – Sigur
    Dec 17, 2014 at 10:12
  • @Sigur No. What I need is something like an arrow from top left to bottom right.
    – Geoff
    Dec 17, 2014 at 10:31

2 Answers 2

13

I introduce \bcancelto{label}{term} by modifying one of the packages routines. EDITED to support labels on \bcancelto.

The modification to \canto@vector to produce \cantox@vector amounted to three things:

1) adding a - before #4 in the \vector call;

2) Changing the ^ superscript to a _ subscript before the \raise; and

3) adding a - sign before #2 following the \raise.

Then I had to define \bcancelto to make this macro substitution and call on \cancelto with the substitution in place.

\documentclass{article}
\usepackage{amsmath}
\usepackage[makeroom]{cancel}
\makeatletter
% #1, #2 offset of label   #6 extra width to clear arrowhead
% #3, #4 vector direction  #7 superscript label style
% #5 vector width          #8 superscript label
\def\cantox@vector#1#2#3#4#5#6#7#8{%
  \dimen@.5\p@
  \setbox\z@\vbox{\boxmaxdepth.5\p@
   \hbox{\kern-1.2\p@\kern#1\dimen@$#7{#8}\m@th$}}%
  \ifx\canto@fil\hidewidth  \wd\z@\z@ \else \kern-#6\unitlength \fi
  \ooalign{%
    \canto@fil$\m@th \CancelColor
    \vcenter{\hbox{\dimen@#6\unitlength \kern\dimen@
      \multiply\dimen@#4\divide\dimen@#3 \vrule\@depth\dimen@\@width\z@
      \vector(#3,-#4){#5}%
    }}_{\raise-#2\dimen@\copy\z@\kern-\scriptspace}$%
    \canto@fil \cr
    \hfil \box\@tempboxa \kern\wd\z@ \hfil \cr}}
\def\bcancelto#1#2{\let\canto@vector\cantox@vector\cancelto{#1}{#2}}
\makeatother
\begin{document}
\noindent
\verb|\cancel{5y}|:
\[ x+\cancel{5y}=0\]
\verb|\bcancel{5y}|:
\[ x+\bcancel{5y}=0\]
\verb|\xcancel{5y}|:
\[ x+\xcancel{5y}=0\]
\verb|\cancelto{\infty}{5y}|:
\[ x+\cancelto{\infty}{5y}=0\]
\noindent NEW! \verb|\bcancelto{\infty}{5y}|:
\[ x+\bcancelto{\infty}{5y}=0\]
\end{document}

enter image description here

0
9

Here is a TikZ solution.

\documentclass[varwidth,border=50]{standalone}
\usepackage{tikz}
\tikzset{
main node/.style={inner sep=0,outer sep=0},
label node/.style={inner sep=0,outer ysep=.2em,outer xsep=.4em,font=\scriptsize,overlay},
strike out/.style={shorten <=-.2em,shorten >=-.5em,overlay}
}
\newcommand{\cancelto}[3][]{\tikz[baseline=(N.base)]{
  \node[main node](N){$#2$};
  \node[label node,#1, anchor=south west] at (N.north east){$#3$};
  \draw[strike out,-latex,#1]  (N.south west) -- (N.north east);
}}
\newcommand{\bcancelto}[3][]{\tikz[baseline=(N.base)]{
  \node[main node](N){$#2$};
  \node[label node,#1, anchor=north west] at (N.south east){$#3$};
  \draw[strike out,-latex,#1]  (N.north west) -- (N.south east);
}}

\begin{document}
  \cancelto[orange]{test}{Oooo!}
    and math
  $\sqrt{\cancelto[red]{x}{\infty}}$

  \bcancelto[orange]{test}{Oooo!}
    and math
  $\sqrt{\bcancelto[red]{x}{\infty}}$
\end{document}

enter image description here

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.