取消套餐向下箭头

取消套餐向下箭头

假设我想取消分数的分母并为其分配一个值。类似这样的事情\cancel{2}\cdot\dfrac{9}{\cancelto{2}{4}}。这里的问题是,之后的分数看起来一点也不好看。所以我需要一个cancelto创建向下箭头的命令。有什么办法吗?

答案1

在...的帮助下蒂克兹您可以定义一个命令来使用向下的箭头来取消表达式:

\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage{cancel}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand*\canc[1]{%
  \mathchoice
    {\scriptstyle#1}
    {\scriptstyle#1}
    {\scriptscriptstyle#1}
    {\scriptscriptstyle#1}
}

\newcommand*\Dcancelto[2][0]{%
  \kern9pt%
  \begin{tikzpicture}[baseline=(current bounding box.center).anchor=west]
    \node[anchor=east,inner sep=2pt] (a) {#2};
    \draw[->] ($(a.north west)+(1pt,-2pt)$) -- ($(a.south east)+(0pt,2pt)$) node at ($(a.south east)+(4pt,1pt)$) {$\canc{#1}$};
\end{tikzpicture}
}

\begin{document} 

\[ \Dcancelto[1]{7} \]

\[ \frac{1}{\Dcancelto[2]{4}} \]

\[ \frac{89}{\Dcancelto[0]{4367}} \]

\[ \cancel{2}\cdot\dfrac{9}{\Dcancelto[2]{4}} \]

\end{document}

结果如下:

答案2

这是另一个基于 Gonzalo 的提议回答回答这个问题。
以下代码为您提供了四个新命令,以便能够从所有四个可能的方向对角划掉并指向(取消到):

  • canceltoSwNe{From}{To}:从西南到东北
    (从左下到右上)对角线交叉
  • canceltoNeSw{From}{To}:从东北向西南
    (右上到左下)斜对角线
  • canceltoSeNw{From}{To}:从东南向西北
    (右下到左上)斜对角线
  • canceltoNwSe{From}{To}:从西北到东南
    (从左上到右下)对角线交叉

一些评论:

  • cancelto与包中的命令相比,这两个参数的顺序是相反的cancel,但我发现这样更合乎逻辑。
  • 边界框与cancel包不同,请参阅背景颜色和分数示例。这可能适合您的需求,也可能不适合。
    所呈现的 cancelto 接受文本或数学作为参数,可以在文本或数学模式下使用。
    所呈现的 cancelto 可以嵌套,与cancelto包中的 cancelto 相反。
  • 从分数示例中可以看出,字体调整大小功能无法正常使用,我无法快速找到解决此问题的简单方法。
    欢迎提出建议!

以下是带有几个示例的代码:

\documentclass{article}

\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.3}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}

\usepackage{cancel}

% ==================================================================================

\usepackage{relsize}

\newcommand\canceltoSwNe[2]{%
    \begin{tikzpicture}[baseline = (B.base)]
        \node[anchor = center, inner sep = 0pt] (B) {#1};
        \draw[arrows = {}-{latex}]%
            ($(B.south west)+(-1pt, -1pt)$) -- ($(B.north east)+(+4pt, +1pt)$)%
                node [anchor = south west, xshift = +1pt, yshift = -1pt,%
                        inner sep = 0pt]%
                    {\smaller\smaller{#2}};
    \end{tikzpicture}%
}

\newcommand\canceltoNeSw[2]{%
    \begin{tikzpicture}[baseline = (B.base)]
        \node[anchor = center, inner sep = 0pt] (B) {#1};
        \draw[arrows = {}-{latex}]%
            ($(B.north east)+(+1pt, +1pt)$) -- ($(B.south west)+(-4pt, -1pt)$)%
                node [anchor = north east, xshift = -1pt, yshift = +1pt,%
                        inner sep = 0pt]%
                    {\smaller\smaller{#2}};
    \end{tikzpicture}%
}

\newcommand\canceltoSeNw[2]{%
    \begin{tikzpicture}[baseline = (B.base)]
        \node[anchor = center, inner sep = 0pt] (B) {#1};
        \draw[arrows = {}-{latex}]%
            ($(B.south east)+(+1pt, -1pt)$) -- ($(B.north west)+(-4pt, +1pt)$)%
                node [anchor = south east, xshift = -1pt, yshift = -1pt,%
                        inner sep = 0pt]%
                    {\smaller\smaller{#2}};
    \end{tikzpicture}%
}

\newcommand\canceltoNwSe[2]{%
    \begin{tikzpicture}[baseline = (B.base)]
        \node[anchor = center, inner sep = 0pt] (B) {#1};
        \draw[arrows = {}-{latex}]%
            ($(B.north west)+(-1pt, +1pt)$) -- ($(B.south east)+(+4pt, -1pt)$)%
                node [anchor = north west, xshift = +1pt, yshift = +1pt,%
                        inner sep = 0pt]%
                    {\smaller\smaller{#2}};
    \end{tikzpicture}%
}

% ==================================================================================

\begin{document}

\noindent%
%
%
Baseline\:%
\colorbox{yellow!30!white}{%
    \canceltoSwNe{Text to cancel}{Text to write}
}\hspace*{5mm}\colorbox{blue!30!white}{%
    $\cancelto{\text{Text to write}}{\text{Text to cancel}}$
}\\
%
Baseline\:%
\colorbox{yellow!30!white}{%
    \canceltoSwNe{Text to cancel}{$x^{2}_{z}$}
}\hspace*{5mm}\colorbox{blue!30!white}{%
    $\cancelto{x^{2}_{z}}{\text{Text to cancel}}$
}\hspace*{25mm}%
%
\colorbox{yellow!30!white}{%
    \canceltoSwNe{$a + 3 \cdot \frac{x}{\alpha}$}{$123$}
}\hspace*{5mm}\colorbox{blue!30!white}{%
    $\cancelto{123}{a + 3 \cdot \frac{x}{\alpha}}$
}\\[5mm]
%
%
Baseline\:%
\colorbox{yellow!30!white}{%
    \canceltoSwNe{$a + 3 \cdot \frac{x}{\alpha}$}{$b - 4 \cdot \frac{\beta}{z}$}
}\hspace*{5mm}\colorbox{blue!30!white}{%
    $\cancelto{b - 4 \cdot \frac{\beta}{z}}{a + 3 \cdot \frac{x}{\alpha}}$
}\\[5mm]
%
%
Baseline\:%
\colorbox{yellow!30!white}{%
    \canceltoSwNe{$xyz$}{$xyz$}
}\hspace*{5mm}\colorbox{blue!30!white}{%
    $\cancelto{xyz}{xyz}$
}\hspace*{15mm}%
%
\colorbox{yellow!30!white}{%
    \canceltoSwNe{$xyz$}{\canceltoSwNe{$xyz$}{$xyz$}}
}\hspace*{5mm}\colorbox{blue!30!white}{%
    $\cancelto{xyz}{\cancelto{xyz}{xyz}}$
}\hspace*{15mm}%
%
\colorbox{yellow!30!white}{%
    \canceltoSwNe{$xyz$}{\canceltoSwNe{$xyz$}{\canceltoSwNe{$xyz$}{$xyz$}}}
}\hspace*{5mm}\colorbox{blue!30!white}{%
    $\cancelto{xyz}{\cancelto{xyz}{\cancelto{xyz}{xyz}}}$
}\\[5mm]
%
%
Baseline\:%
\colorbox{yellow!30!white}{%
    $\frac{1}{\canceltoSwNe%
        {$x + y + z^{2} - \lim\limits_{a \rightarrow \infty} \frac{1}{a}$}%
            {A very, very long text}}$
}\hspace*{5mm}\colorbox{blue!30!white}{%
    $\frac{1}{\cancelto{\text{A very, very long text}}%
        {x + y + z^{2} - \lim\limits_{a \rightarrow \infty} \frac{1}{a}}}$
}\\[10mm]

\noindent%
%
%
Baseline\:%
\colorbox{yellow!30!white}{%
    \canceltoSwNe{$a + 3 \cdot \frac{x}{\alpha}$}{$b - 4 \cdot \frac{\beta}{z}$}
}\hspace*{5mm}\colorbox{yellow!30!white}{%
    \canceltoNeSw{$a + 3 \cdot \frac{x}{\alpha}$}{$b - 4 \cdot \frac{\beta}{z}$}
}\hspace*{5mm}\colorbox{yellow!30!white}{%
    \canceltoSeNw{$a + 3 \cdot \frac{x}{\alpha}$}{$b - 4 \cdot \frac{\beta}{z}$}
}\hspace*{5mm}\colorbox{yellow!30!white}{%
    \canceltoNwSe{$a + 3 \cdot \frac{x}{\alpha}$}{$b - 4 \cdot \frac{\beta}{z}$}
}

\end{document}

% ==================================================================================

结果如下:

自定义的 cancelto 命令

答案3

要更改箭头方向,您需要重写包的大部分内部结构cancel。我不建议这样做,因为这是非常复杂的代码。也许您可以尝试其他一些选项,例如

\begin{equation}
\bcancel{2}\cdot\dfrac{9}{{\bcancel{4}}^2_{}}
\end{equation}

或者

\begin{equation}
\cancel{2}\cdot\dfrac{9}{{\cancel{4}\rule{0pt}{2.ex}}^{\;2}_{}}
\end{equation}

相关内容