取消包:结合 bcancel 和 cancelto(bcancelto?)

取消包:结合 bcancel 和 cancelto(bcancelto?)

有没有办法用cancel包创建负斜率,但使用\cancelto?即我想结合这两个命令,这样我就有一个负斜率,但带有箭头和数字。

谢谢!

梅威瑟:

\documentclass{journal}
\usepackage{cancel}

\begin{document}
\[
\cancelto{0}{X^2}
\]
\[
\bcancel{X^2}
\]
%$\bcancelto{0}{X^2}$
\end{document}

在此处输入图片描述

答案1

我认为这就是你所追求的:

取消至右下角示例

这是通过首先修补\canto@vector命令来更改脚本位置来实现的,该命令基于向量 y 分量的符号(由 给出#4)。然后,\@cancelto使用可选参数更新。如果为空,则将实现标准行为。如果-传递了 a,则向量指向下方。最后,\bcancelto创建命令,假设smaller使用默认选项(Smallersamesize需要替代定义来修改使用的脚本大小)。

您修改后的 MWE:

\documentclass{article}
\usepackage{cancel}

\usepackage{etoolbox}
\makeatletter

    %patch \canto@vector to correctly place script.
    \pretocmd{\canto@vector}{\edef\testneg{#4<0}}{}{\@latex@error{Patch fail}}
    \patchcmd{\canto@vector}{^}{\ifnum\testneg_\else^\fi}{}{\@latex@error{Patch fail}}
    \patchcmd{\canto@vector}{\raise#2\dimen@}{\raise\dimexpr\ifnum\testneg-\ht\z@+\fi#2\dimen@}{}{\@latex@error{Patch fail}}

    \renewcommand\@cancelto[5][]{%
        \OriginalPictureCmds\@begin@tempboxa\hbox{\m@th$#4{#5}$}%
        \dimen@\width % wide
        \@min@pt\dimen@ 2\@min@pt\totalheight4
        \ifdim\totalheight<\dimen@
         \@tempcnta\totalheight \multiply\@tempcnta 5 \divide\@tempcnta\dimen@
         \@tempdimb 3\p@ % extra width for arrowhead ("+2")
         \advance\dimen@ \ifcase\@tempcnta 5\or 5\or 4\or 3\else 2\fi \p@
         \@min@pt\dimen@9\advance\dimen@\p@ 
         \edef\@tempa{\ifcase\@tempcnta 544{#1 1}\or 544{#1 1}\or 542{#1 1}\or 444{#1 3}\else 361{#1 1}\fi
              {\strip@pt\dimen@}{\strip@pt\@tempdimb}}%
         \def\@tempb{Cancel #4 to #2; case wide }%
        \else % tall
         \advance\totalheight3\p@ % "+2"
         \@tempcnta\dimen@ \multiply\@tempcnta 5 \divide\@tempcnta\totalheight
         \advance\totalheight3\p@ % "+2"
         \dimen@ \ifcase\@tempcnta .25\or .25\or .5\or .75\else 1\fi \totalheight
         \@tempdimb \ifcase\@tempcnta .8\or .8\or 1.2\or 1.5\else 2\fi \p@
         \edef\@tempa{\ifcase\@tempcnta 081{#1 4}\or 081{#1 4}\or 181{#1 2}\or 273{#1 4}\else 361{#1 1}\fi
              {\strip@pt\dimen@}{\strip@pt\@tempdimb}}%
        \fi
        \dimen@\height
        \setbox\@tempboxa\hbox{$\m@th\vcenter{\box\@tempboxa}$}%
        \advance\dimen@-\height % the difference in height
        \unitlength\p@ \canc@thinlines
        {\/\raise\dimen@\hbox{\expandafter\canto@vector\@tempa{#2}{#3}}}%
        \@end@tempboxa
    }

    \def\bcancelto#1#2{\mathchoice    %  smaller option (default)
      {\@cancelto[-]\textstyle{#1}\displaystyle{#2}}%
      {\@cancelto[-]\scriptstyle{#1}\textstyle{#2}}%
      {\@cancelto[-]\scriptscriptstyle{#1}\scriptstyle{#2}}%
      {\@cancelto[-]\scriptscriptstyle{#1}\scriptscriptstyle{#2}}%
      }
\makeatother
\begin{document}
\[
\cancelto{0}{X^2}
\]
\[
\bcancel{X^2}
\]
\[
\bcancelto{0}{X^2}
\]
\end{document}

需要注意的是,我建议使用makeroom选项来容纳箭头\bcancelto

相关内容