使用 tikzmark 包取消术语

使用 tikzmark 包取消术语

最近,@marmot 在需要帮助来创建一个更灵活的 \cancel 命令,该命令可以在对齐环境中工作建议使用\tikzmarknode该软件包最新版本(1.6)的命令来完成与该软件包命令tikzmark相同的工作。我试图找出一种类似的方法来实现该命令,但没有成功。\cancelcancel\cancelto

据我了解,要取消的整个表达式被命令变成一个节点\tikzmarknode,并从路径图片(节点)的西南角到其东北角画一条线。我可以将这条线转换成箭头,但我无法在东北角的右上角显示要取消的值,因为它在边界框之外。

我也尝试过解决方案https://tex.stackexchange.com/a/218486/95438https://tex.stackexchange.com/a/234601/95438,但前者排版不正确,而最后一个尽管正是我想要的,但却丢失了它的方程编号。

我怎样才能获得与最后一次尝试相同的排版,但使用 tikzmark 包以免丢失方程编号?

感谢您的任何帮助!

\documentclass[mainlanguage=english,babel={main=english,french,brazil},sepcorpaffilfrench={,~},sepcorpaffilenglish={,~},version=inprogress]{yathesis}
%\documentclass{book}
%\documentclass{article}
%
% If using XeLaTex or LuaLaTex
%\usepackage{fontspec}
%
% If using LaTex or PdfLaTex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
%
\usepackage{lmodern} % latin modern font
\usepackage{amsmath}
\usepackage{cancel} % draw diagonal lines  ("cancelling" a term)
%
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{cancel/.style={path picture={
            \draw[#1] (path picture bounding box.south west) -- (path picture bounding box.north east);
}}}
%
%%% My try
\tikzset{cancelto/.style={path picture={
            \draw[#1,->,-latex] (path picture bounding box.south west) -- (path picture bounding box.north east) node[anchor=south west] at (path picture bounding box.north east) {1};
}}}
%
%%% From https://tex.stackexchange.com/a/218486/95438
\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{\cancelt}[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);
}}
%
%%% From https://tex.stackexchange.com/a/234601/95438
\tikzset{block/.style = {anchor = center, inner sep = 0pt,
        execute at begin node={\begin{varwidth}{1.5\linewidth}},  %% change 0.5 as you wish
            execute at end node={\end{varwidth}}
    }
}
\usepackage{relsize}
\usetikzlibrary{calc}
\newcommand\canceltoSwNe[2]{%
    \begin{tikzpicture}[baseline = (B.base)]
    \node[block] (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}%
}
%
\begin{document}
    \begin{align}
    \begin{split}
    &= \mp \cos^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau \\
    &\mathrel{\phantom{=}} \tikzmarknode[cancel]{cc}{\pm \frac{1}{2} \sin \left[ 4\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \cos \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau} \\
    &\mathrel{\phantom{=}} \tikzmarknode[cancel]{cc}{\mp \frac{1}{2} \sin \left[ 4\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \cos \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau} \\
    &\mathrel{\phantom{=}} \mp \sin^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    \begin{split}
    &= \mp \left\lbrace \tikzmarknode[cancelto]{cc}{\cos^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] + \sin^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right]} \right\rbrace \\
    &\mathrel{\phantom{=}} \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    \begin{split}
    &= \mp \left\lbrace \cancelt{\cos^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] + \sin^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right]}{1} \right\rbrace \\
    &\mathrel{\phantom{=}} \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    \begin{split}
    &= \mp \left\lbrace \canceltoSwNe{\[\cos^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] + \sin^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right]\]}{1} \right\rbrace \\
    &\mathrel{\phantom{=}} \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    &= \mp \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{align}
\end{document}

输出:

在此处输入图片描述

答案1

路径图片具有剪掉边界框外所有内容的属性,否则您的方法就奏效了。但让它奏效很容易。

\documentclass[mainlanguage=english,babel={main=english,french,brazil},sepcorpaffilfrench={,~},sepcorpaffilenglish={,~},version=inprogress]{yathesis}
%\documentclass{book}
%\documentclass{article}
%
% If using XeLaTex or LuaLaTex
%\usepackage{fontspec}
%
% If using LaTex or PdfLaTex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
%
\usepackage{lmodern} % latin modern font
\usepackage{amsmath}
\usepackage{cancel} % draw diagonal lines  ("cancelling" a term)
%
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{cancel/.style={path picture={
            \draw[#1] (path picture bounding box.south west) -- (path picture bounding box.north east);
}}}
%
%%% My try
\tikzset{cancelto/.style={path picture={
\node[anchor=north east,font=\small] (aux) at (path picture bounding box.north east) {1};
\draw[#1,-latex] (path picture bounding box.south west) -- (aux);
}}}
%
%%% From https://tex.stackexchange.com/a/218486/95438
\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{\cancelt}[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);
}}
%
%%% From https://tex.stackexchange.com/a/234601/95438
\tikzset{block/.style = {anchor = center, inner sep = 0pt,
        execute at begin node={\begin{varwidth}{1.5\linewidth}},  %% change 0.5 as you wish
            execute at end node={\end{varwidth}}
    }
}
\usepackage{relsize}
\usetikzlibrary{calc}
\newcommand\canceltoSwNe[2]{%
    \begin{tikzpicture}[baseline = (B.base)]
    \node[block] (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}%
}
%
\begin{document}
    \begin{align}
    \begin{split}
    &= \mp \cos^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau \\
    &\mathrel{\phantom{=}} \tikzmarknode[cancel]{cc}{\pm \frac{1}{2} \sin \left[ 4\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \cos \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau} \\
    &\mathrel{\phantom{=}} \tikzmarknode[cancel]{cc}{\mp \frac{1}{2} \sin \left[ 4\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \cos \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau} \\
    &\mathrel{\phantom{=}} \mp \sin^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    \begin{split}
    &= \mp \left\lbrace \tikzmarknode[cancelto]{cc}{\cos^{2} \left[ 2\pi\left( 
    \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] + \sin^{2} \left[
    2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right]\,~} \right\rbrace \\
    &\mathrel{\phantom{=}} \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    \begin{split}
    &= \mp \left\lbrace \cancelt{\cos^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] + \sin^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right]}{1} \right\rbrace \\
    &\mathrel{\phantom{=}} \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    \begin{split}
    &= \mp \left\lbrace \canceltoSwNe{\[\cos^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] + \sin^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right]\]}{1} \right\rbrace \\
    &\mathrel{\phantom{=}} \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    &= \mp \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{align}
\end{document}

在此处输入图片描述

顺便说一句,在您的问题中,您现在使用了两个不同答案的宏/方法,因此对于不熟悉之前帖子的人来说,很难回答您的问题。因此,我恳请您将以后的问题减少到最低限度,以鼓励更多用户回答这些问题,并让您获得更快、更好的答案。

相关内容