答案1
欢迎来到 Tex.SE!
众多解决方案之一:
\documentclass[varwidth,border=30]{standalone}
\usepackage{tikz}
\tikzset{main node/.style={inner sep=0,outer sep=0},
label node/.style={inner sep=0,outer ysep=.2em,outer xsep=.4em,font=\scriptsize,overlay},
strike out/.style={shorten <=-.2em,shorten >=-.5em,overlay}}
\newcommand{\cancelto}[3][]{\tikz[baseline=(N.base)]{
\node[main node](N){$#2$};
\node[label node,#1, anchor=south west] at (N.north east){$#3$};
\draw[-,#1] (N.south west) -- (N.north east)}}
\begin{document}
\cancelto[purple]{Text}{no!}
and math
$\cancelto[blue]{x^3}{x^2}$
\end{document}
答案2
如果您只是想删除箭头,您可以\canto@vector
使用 patch 来\line
代替\vector
。
\documentclass{article}
\usepackage{xcolor}
\usepackage[Smaller]{cancel}
\usepackage{xpatch}% to patch \cancel
\makeatletter
\xpatchcmd{\canto@vector}{\vector}{\line}{}{}
\makeatother
\renewcommand{\CancelColor}{\color{green!80!red}}
\begin{document}
\[
\cancelto{x^2}{x^3}
\]
\end{document}