2

I found this helpful to quelling my issue with the cancel packages arrows but displaymath seems to break it.

The only part of the linked code I am using is

\usepackage{tikz}
\usepackage{relsize}
\usetikzlibrary{calc}
\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}%                                                            
}

It would be great if this code would just inherent the environment it is being used in. In my case, the align environment. However, it doesn't and I have to insert math delimiters. If I use \(\), everything works but is disproportional since this is for inline math. I tried using \[\] but it just breaks down instead.

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

\usepackage{tikz}
\usepackage{relsize}
\usetikzlibrary{calc}
\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}%                                                            
}
\begin{document}
\begin{align*}
  L\{2\cos(3t)\}(s)
   & = 2\int_0^{\infty}\cos(3t)e^{-st}dt\\
   & = \canceltoSwNe{\(\frac{2e^{-st}\sin(3t)}{3}\biggl|_0^{\infty}\)}{\(0\)} +
   \frac{s}{3}\int_0^{\infty}\sin(3t)e^{-st}dt
\end{align*}
\begin{align*}
  L\{2\cos(3t)\}(s)
   & = 2\int_0^{\infty}\cos(3t)e^{-st}dt\\
   & = \canceltoSwNe{\[\frac{2e^{-st}\sin(3t)}{3}\biggl|_0^{\infty}\]}{\[0\]} +
   \frac{s}{3}\int_0^{\infty}\sin(3t)e^{-st}dt
\end{align*}
\end{document}

enter image description here

dustin
  • 18,617
  • 23
  • 99
  • 204
  • 1
    Do you need \displaystyle? Sinces \[ handles some vertical-mode-issue, it is not surprised that it fails to work with TikZ and align. – Symbol 1 Mar 23 '15 at 02:41
  • @Symbol1 \displaystyle can be a short term solution but I would like to see something better. – dustin Mar 23 '15 at 03:41

1 Answers1

4

You need to specify the text width for \[...\] to work. This can be done with varwidth package to emulate the minipage/parbox mode.

\documentclass{article}
\usepackage[makeroom]{cancel}
\usepackage{mathtools}
\usepackage{varwidth}

\usepackage{tikz}
\tikzset{block/.style = {anchor = center, inner sep = 0pt,
                          execute at begin node={\begin{varwidth}{0.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*}
  L\{2\cos(3t)\}(s)
   & = 2\int_0^{\infty}\cos(3t)e^{-st}dt\\
   & = \canceltoSwNe{\(\frac{2e^{-st}\sin(3t)}{3}\biggl|_0^{\infty}\)}{\(0\)} +
   \frac{s}{3}\int_0^{\infty}\sin(3t)e^{-st}dt
\end{align*}
\begin{align*}
  L\{2\cos(3t)\}(s)
   & = 2\int_0^{\infty}\cos(3t)e^{-st}dt\\
   & = \canceltoSwNe{\[\frac{2e^{-st}\sin(3t)}{3}\biggl|_0^{\infty}\]}{0} +
   \frac{s}{3}\int_0^{\infty}\sin(3t)e^{-st}dt
\end{align*}
\end{document}

enter image description here

  • Great answer but is there anyway to just have canceltoSwNe just inherit the environment it is being used in? – dustin Mar 23 '15 at 14:49