后续:改进方程式中删除项的排版

后续:改进方程式中删除项的排版

这是我之前关于改进方程式中删除项的排版. 提出的解决方案@土拨鼠效果很好,但我必须对间距进行比我预期更多的手动调整。根本问题似乎是划掉术语的箭头顶部的标签影响了术语之间的间距。这体现在下图所示的两个问题中:

在此处输入图片描述

以上内容是使用以下(不是最小的)MWE 生成的。它基本上等于建议的解决方案,但有一些附加功能,使我可以调整箭头尖端的位置以及文本相对于箭头尖端的位置。

\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}

说了这么多,我的问题是:如何在不改变等式间距的情况下删除一个术语并在箭头尖端添加文本?

答案1

overlay在键中添加了一个选项,这样就无需手动添加空格了。(除了使用距离之外,您还可以考虑仅调整标签节点的锚点。)

\documentclass{article}
\usepackage{cancel}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,tikzmark}
\newif\ifCancelToOverlay
\tikzset{CancelTo/.is family,
CancelTo,
angle/.initial=60,
name/.initial=tmp,
node/.style={},
arrow/.style={->},
topoffs/.initial=2pt, 
nodeaboveoffs/.initial=1pt,
nodeleftoffs/.initial=0pt,
overlay/.is if=CancelToOverlay
}
\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{\ifCancelToOverlay
  \xdef\mydist{0pt}
  \else 
  \xdef\mydist{\x1}
  \fi};
\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,overlay=true]{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,overlay=true]{ignore}{(a+b)\pd{f}{x}} +
  \pd{g}{y} = 0
\end{equation}
\end{document}

在此处输入图片描述

相关内容