1

I have very similar lines in math mode under a \align environment. When I use \cancel or \bcancel it doesn't draw parallel lines for what should be similar width terms.

I think a simple repro would be:

\begin{align}
    f &= \left(\cancel{\frac{\partial v}{\partial x}}\right) \\
    g &= \left(\cancel{\frac{\partial v}{\partial z}}\right)
\end{align}

cancel non-parallel

I tried to cook up some tikz based solutions off of this issue, but the dont work well with say \left(\frac{\partial u}{\partial y} + \cancel{\frac{\partial v}{\partial z}}\right) and produce something like tikz math

edit:

6
  • I guess the documentation of the cancel package recommends against using it in math mode, but I can't find a simpler alternative.
    – hax0r
    Commented Nov 18, 2020 at 7:58
  • 2
    The x is minimally wider than z, enough to trigger the different slope. You could try with something like \cancel{\mkern1mu\frac{\partial v}{\partial z}\mkern1mu} but it's surely not elegant...
    – campa
    Commented Nov 18, 2020 at 8:24
  • Thanks! That certainly works, even though it might not be the most elegant solution for a general case, it's a quick fix. I'm happy to just create a custom cancel command with this for now
    – hax0r
    Commented Nov 18, 2020 at 18:08
  • 1
    Since the slant of the cancellation on the fraction with the "z" is a bit more attractive (in my eyes), you might adapt @campa's suggestion to instead use \mkern(-1mu) on the fraction with the "x". Commented Nov 19, 2020 at 2:55
  • Bad luck to land right at a transition between slopes. Adding (or subtracting) a small width to both fractions will give equal slope selection. In the red-slash example, the color changing has lost the math context (unnecessarily). Put \displaystyle right before \frac. Commented Nov 19, 2020 at 9:53

1 Answer 1

0

The \cancel macro uses internally picture mode, and measures the width and height of its argument to decide the slope of the stroke. The code

\documentclass{article}
\begin{document}
\setbox0=\hbox{$x$}\showthe\wd0
\setbox0=\hbox{$z$}\showthe\wd0
\end{document}

returns

> 5.71527pt.
l.3 \setbox0=\hbox{$x$}\showthe\wd0
> 5.0903pt.
l.4 \setbox0=\hbox{$z$}\showthe\wd0

so the x is minimally wider than the z; minimally, and yet enough to trigger the different slope. The quickest (and lest elegant) solution is to add some manual kerning around the symbols.

I implement here this "solution" by the following work-around: the original definition of \cancel in cancel.sty is

\DeclareRobustCommand\cancel[1]{\ifmmode
  \mathpalette{\@cancel{\@can@slash{}}}{#1}\else 
  \@cancel{\@can@slash{}}\hbox{#1}\fi}

I patch this (hoping Donald won't mind) by adding an optional argument which adds some kerning to the argument of \cancel and subtracts it outside of the cancelled expression, such that the total width remains unchanged.

\documentclass{article}

\usepackage{cancel}

\makeatletter
\DeclareRobustCommand\cancel[2][0]{%
  \ifmmode
    \mkern-#1mu
    \mathpalette{\@cancel{\@can@slash{}}}{\mkern#1mu #2 \mkern#1mu}%
    \mkern-#1mu
  \else
    \dimen@=\dimexpr 1em*#1/18\relax
    \kern-\dimen@
    \@cancel{\@can@slash{}}\hbox{\kern\dimen@ #2\kern\dimen@}%
    \kern-\dimen@
  \fi}
\makeatother

\begin{document}

\[
\cancel{\frac{\partial v}{\partial x}}
\quad
\cancel[1]{\frac{\partial v}{\partial z}}
\quad
\cancel[-1]{\frac{\partial v}{\partial x}}
\quad
\cancel{\frac{\partial v}{\partial z}}
\]

\end{document}

enter image description here

Whether you want to add some width to the fraction containing z or subtract it from the fraction containing x, as Barbara Beeton suggested in her comment), is a matter of taste. (I agree with Barbara, but de gustibus...)

1
  • Thanks for taking the time to investigate this in detail and for providing a generalizable solution.
    – hax0r
    Commented Nov 19, 2020 at 17:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .