I need to strike out terms in equations. Based on the answers to this question, I've tried the cancel package, but the appearance of the resulting output does not convince me. Consider this example:

\newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}}
    + \cancelto{\mathrm{ignored}}{\pd{g}{y}} + \pd{h}{z}

This gives the following output:

enter image description here

If I use the package option makeroom, I get:

enter image description here

This is obviously unsatisfactory. What I would like to be able to do:

  • Arrow shapes consistent with those used by TikZ.
  • Arrow that are parallel (I would imagine this is difficult to do, so I would be happy to specify the angles manually).
  • Ability to specify the anchor of the text at the arrow tip (so that the text could be anchored at the bottom center or bottom right, for example).
  • Ability to specify the font size of the text near the arrow tip (which I don't seem to be able to do with \cancelto).
  • Automatically add space between the terms similar to what makeroom does (nice to have, but not essential if I can change the font) size because I can fine-tune the spacing if necessary).

Thanks for your help.


Here is a proposal which comes with some pgfkeys that allow you to adjust the angle, the font and the arrow at will. (EDIT: Fixed an angle, big thanks to user1362373!)

\tikzset{CancelTo/.is family,
\begin{tikzpicture}[overlay,remember picture]
\draw[/tikz/CancelTo/arrow] let \p1=($(\pgfkeysvalueof{/tikz/CancelTo/name}.north)-(\pgfkeysvalueof{/tikz/CancelTo/name}.south)$),\n1={0.5*\y1*cot(\pgfkeysvalueof{/tikz/CancelTo/angle})},
in ([xshift=-\n1]\pgfkeysvalueof{/tikz/CancelTo/name}.south) -- ++ (\pgfkeysvalueof{/tikz/CancelTo/angle}:\n2+5pt) 
node[above right,/tikz/CancelTo/node] (tmplabel) {#2};
\path let \p1=($(tmplabel.north east)-(\pgfkeysvalueof{/tikz/CancelTo/name}.east)$) in
\newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}}
An equation.
    + \CancelTo[node/.style={font=\tiny,text=blue}]{ignored}{\pd{g}{y}} + \pd{h}{z}
Another equation with another angle.
    + \CancelTo[angle=70]{ignored}{\pd{g}{y}} + \pd{h}{z}
Bonus: you can name nodes and use \tikzmarknode{this}{this} otherwise.
\begin{tikzpicture}[overlay,remember picture]
\draw[-latex,red] (this) to[bend right] (mynode);

enter image description here

  • Thanks, this does mostly what I need, I can take care of some of the fine-tuning. One thing that would be nice would be for the vertical locations of the top and bottom of the arrows to be consistent. Now the bottom of the arrow for the dg/dy term is lower than for the df/dx term. – user1362373 Jan 14 '19 at 6:41
  • @user1362373 Yes, this is because y goes below the baseline whereas x does not. Would it be acceptable to just insert a \vphantom{y} in the derivatives w.r.t. x? One way to achieve this is to use \newcommand{\pd}[2]{\frac{\partial #1\vphantom{y}}{\partial #2\vphantom{y}}}. – user121799 Jan 14 '19 at 12:19
  • In \n2={\y1/sin(60), shouldn't you also use \pgfkeysvalueof{/tikz/CancelTo/angle}? – user1362373 Jan 17 '19 at 6:01
  • @user1362373 Absolutely! Thanks a lot! – user121799 Jan 17 '19 at 6:08
  • Another question: In \tikzmarknode{\pgfkeysvalueof{/tikz/CancelTo/name}}{#3}, I assume you're assigning the value of the third argument to the angle. But in that case, why doesn't it say /tikz/CancelTo/angle? (I'm asking because I'm trying to add further optional arguments to fine-tune the spacing, but failing miserably, so I'm trying to understand the details of what you've done.) – user1362373 Jan 17 '19 at 6:18

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.