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}
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...)
x
is minimally wider thanz
, 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...\mkern(-1mu)
on the fraction with the "x".