2

I am using the package cancel to do the operation as shown in figure. pic

As you can see the arrow is choppy. I read another question mentioning the same error : here. As suggested in the accepted answer : I can use the pict2e package in normal cases but for cancel this is a documented issue with the solution being (as far as I get it), add the line \@ifundefined{OriginalPictureCmds}{\let\OriginalPictureCmds\relax}{} to my document preamble.

This results in an error and doesn't work out. The error is : ! You can't use '\spacefactor' in vertical mode.

Can someone please help me make this work so that the arrow is smooth?

Nitin
  • 295
  • 1
  • 11

1 Answers1

3

Here is a solution using tikz.

enter image description here

We define a new command \cancelto that takes three arguments, one optional. The first required argument is the "to" expression, which is 0 in the example. You could use \scriptsize{0} if you want it smaller. The second required argument is the expression that is to be cancelled. The calling sequence is

\cancelto[<height>]{<to>}{<expression>}

The optional argument adjusts the angle of the arrow by specifying the height above and below the cancelled expression. In the example it is set to 3ex. I set the default to .5ex.

First the lengths \hght and \wdth capture the height and width of the expression using \widthof and \heightof (from the calc package). Then an arrow is drawn inside a box of 0 size (to overlap the expression). Then the expression is placed.

Here is the code:

\documentclass{article}

\usepackage{calc}
\usepackage{tikz}

\newlength{\hght}
\newlength{\wdth}

\newcommand{\cancelto}[3][.5ex]{\setlength{\hght}{\heightof{$#3$}}\setlength{\wdth}{\widthof{$#3$}}%
    \makebox[0pt][l]{\tikz[baseline]{\draw[-latex](0,-#1)--(\wdth,\hght+#1) node[shift={(1mm,.5mm)}]{#2};}}#3}

\begin{document}

\[
\sqrt{\frac{i}{2}}\sqrt{\frac{i-1}{2}}\cancelto[3ex]{0}{\{e^{it_1E_{i,i-1}}e^{it_2E_{i-1,i-2}}-e^{it_2E_{i,i-1}}e^{it_1E_{i-1,i-2}}\}}
\]

\end{document}

Here the optional argument is set to its default, .5ex:

enter image description here

Of course, you can adjust the line thickness, color, arrowhead, etc. as you would anything you \draw with tikz.

Sandy G
  • 42,558
  • I approve of your code and your ability. :-) – Sebastiano May 28 '20 at 21:58
  • 1
    @Sebastiano, your kindness makes the world a better place. – Sandy G May 28 '20 at 22:04
  • Thanks, this is a nice answer. Can you point out the following as well? i) How did you know that tikz would do the trick? ii) Any way to do this without invoking any other package? I really want to get the same result with cancel package. – Nitin May 29 '20 at 08:45
  • 1
    @Nitin, tikZ has become the standard for most graphics in LaTeX. Commands from the picture environment (\put, \line, \vector, \circle) can sometimes used for basic tasks, but their scope is limited. In particular, the \line and \vector commands only accept integers between -4 and 4 for slopes. The cancel package uses these commands and so can't really be fixed without a complete overhaul, which honestly would probably use tikZ. – Sandy G May 29 '20 at 14:09
  • 1
    If you're really opposed to using tikZ, you could use the ideas from this solution to create an arrow that has the appropriate length and then use \rotatebox from the graphicx package. But tikZ makes this much easier. – Sandy G May 29 '20 at 14:13
  • Yes, now I get it. I thought that cancel was not using these commands. My main purpose to avoid tikz was to keep my preamble as short as possible. Anyways, I got it now. Thanks again. :) – Nitin May 29 '20 at 16:58