This is a follow-up question to my earlier question about Improving typesetting of striking out terms in equations. The solution proposed by @marmot works well, but I have to make more manual adjustments to the spacing than I expected. The fundamental problem appears to be that the label at the top of the arrow that strikes out a term influences the spacing between the terms. This manifests in two problems shown in the following picture:
The above was generated with the following (not quite minimal) MWE. It is basically equal to the proposed solution with some additions to allow me to adjust the position of the tip of the arrow and the position of the text relative to the tip of the arrow.
\documentclass{article}
\usepackage{cancel}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,tikzmark}
\tikzset{CancelTo/.is family,
CancelTo,
angle/.initial=60,
name/.initial=tmp,
node/.style={},
arrow/.style={->},
topoffs/.initial=2pt,
nodeaboveoffs/.initial=1pt,
nodeleftoffs/.initial=0pt
}
\newcommand{\CancelTo}[3][]{\bgroup\tikzset{CancelTo/.cd,#1}
\tikzmarknode{\pgfkeysvalueof{/tikz/CancelTo/name}}{#3}
\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})},\n2={\y1/sin(\pgfkeysvalueof{/tikz/CancelTo/angle})}
in ([xshift=-\n1]\pgfkeysvalueof{/tikz/CancelTo/name}.south) -- ++ (\pgfkeysvalueof{/tikz/CancelTo/angle}:\n2+\pgfkeysvalueof{/tikz/CancelTo/topoffs})
node[above left=\pgfkeysvalueof{/tikz/CancelTo/nodeaboveoffs} and \pgfkeysvalueof{/tikz/CancelTo/nodeleftoffs},inner sep=0pt,font=\scriptsize,/tikz/CancelTo/node] (tmplabel) {#2};
\path let \p1=($(tmplabel.north east)-(\pgfkeysvalueof{/tikz/CancelTo/name}.east)$) in
\pgfextra{\xdef\mydist{\x1}};
\end{tikzpicture}\egroup\vphantom{\cancelto{#2}{#3}}\hspace{\mydist}}
\newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}}
\begin{document}
\textbf{Problem 1 (``narrow" term):}
With zero offset:
\begin{equation}
\CancelTo[nodeleftoffs=0pt]{ignore}{\pd{f}{x}} +
\pd{g}{y} = 0
\end{equation}
With offset of $-11$pt:
\begin{equation}
\CancelTo[nodeleftoffs=-11pt]{ignore}{\pd{f}{x}} +
\pd{g}{y} = 0
\end{equation}
What I would like to get (spacing between first fraction and $+$ unaffected):
\begin{equation}
\CancelTo[nodeleftoffs=-11pt]{ignore}{\pd{f}{x}} \!\!\!\!\!\! +
\pd{g}{y} = 0
\end{equation}
\textbf{Problem 2 (``wide" term):}
Equation without arrow:
\begin{equation}
(a+b)\pd{f}{x} + \pd{g}{y} = 0
\end{equation}
Equation with arrow and zero offset:
\begin{equation}
\CancelTo[nodeleftoffs=0pt]{ignore}{(a+b)\pd{f}{x}} +
\pd{g}{y} = 0
\end{equation}
What I would like to get (spacing between first fraction and $+$ unaffected):
\begin{equation}
\CancelTo[nodeleftoffs=-11pt]{ignore}{(a+b)\pd{f}{x}} \;\, +
\pd{g}{y} = 0
\end{equation}
\end{document}
Having said all this, my question is the following: How can I strike out a term and add text at the tip of the arrow without changing the spacing in the equation?


cancelversion, together with makeroom, has them, too. If you addoverlay=trueafter (say)overlay/.is if=CancelToOverlay,the default will be true but you can addoverlay=falsewhenever you want to have the space inserted. – Jan 17 '19 at 17:38