使用向下箭頭取消數學表達式

使用向下箭頭取消數學表達式

下列 解決方案問題要取消一些數學文字的地方可以使用該cancel套件。巨集\cancelto會產生一個從左下角到右上角的箭頭。它還提供了一個名為 的宏\bcancel,該宏給出從左上角到右下角的刪除線。

是否有可能有一個將這兩者結合在一起的宏,其形式為\bcancelto:從左上角到右下角的箭頭。

這是一個 MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage[makeroom]{cancel}

\begin{document}
\noindent
\verb|\cancel{5y}|:
\[ x+\cancel{5y}=0\]
\verb|\bcancel{5y}|:
\[ x+\bcancel{5y}=0\]
\verb|\xcancel{5y}|:
\[ x+\xcancel{5y}=0\]
\verb|\cancelto{\infty}{5y}|:
\[ x+\cancelto{\infty}{5y}=0\]

\end{document}

答案1

\bcancelto{label}{term}透過修改其中一個套件例程來介紹。編輯以支援\bcancelto.

\canto@vector生產的修改\cantox@vector包括三件事:

1)在呼叫中加入-before ;#4\vector

2) 將;之前的^上標改為下標和_\raise

3)在後面加上一個-符號。#2\raise

然後我必須定義以進行此巨集替換並在替換到位後\bcancelto進行調用。\cancelto

\documentclass{article}
\usepackage{amsmath}
\usepackage[makeroom]{cancel}
\makeatletter
% #1, #2 offset of label   #6 extra width to clear arrowhead
% #3, #4 vector direction  #7 superscript label style
% #5 vector width          #8 superscript label
\def\cantox@vector#1#2#3#4#5#6#7#8{%
  \[email protected]\p@
  \setbox\z@\vbox{\boxmaxdepth.5\p@
   \hbox{\kern-1.2\p@\kern#1\dimen@$#7{#8}\m@th$}}%
  \ifx\canto@fil\hidewidth  \wd\z@\z@ \else \kern-#6\unitlength \fi
  \ooalign{%
    \canto@fil$\m@th \CancelColor
    \vcenter{\hbox{\dimen@#6\unitlength \kern\dimen@
      \multiply\dimen@#4\divide\dimen@#3 \vrule\@depth\dimen@\@width\z@
      \vector(#3,-#4){#5}%
    }}_{\raise-#2\dimen@\copy\z@\kern-\scriptspace}$%
    \canto@fil \cr
    \hfil \box\@tempboxa \kern\wd\z@ \hfil \cr}}
\def\bcancelto#1#2{\let\canto@vector\cantox@vector\cancelto{#1}{#2}}
\makeatother
\begin{document}
\noindent
\verb|\cancel{5y}|:
\[ x+\cancel{5y}=0\]
\verb|\bcancel{5y}|:
\[ x+\bcancel{5y}=0\]
\verb|\xcancel{5y}|:
\[ x+\xcancel{5y}=0\]
\verb|\cancelto{\infty}{5y}|:
\[ x+\cancelto{\infty}{5y}=0\]
\noindent NEW! \verb|\bcancelto{\infty}{5y}|:
\[ x+\bcancelto{\infty}{5y}=0\]
\end{document}

在此輸入影像描述

答案2

這是一個 TikZ 解決方案。

\documentclass[varwidth,border=50]{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[strike out,-latex,#1]  (N.south west) -- (N.north east);
}}
\newcommand{\bcancelto}[3][]{\tikz[baseline=(N.base)]{
  \node[main node](N){$#2$};
  \node[label node,#1, anchor=north west] at (N.south east){$#3$};
  \draw[strike out,-latex,#1]  (N.north west) -- (N.south east);
}}

\begin{document}
  \cancelto[orange]{test}{Oooo!}
    and math
  $\sqrt{\cancelto[red]{x}{\infty}}$

  \bcancelto[orange]{test}{Oooo!}
    and math
  $\sqrt{\bcancelto[red]{x}{\infty}}$
\end{document}

在此輸入影像描述

相關內容