4

How to make TikZ cancel "overlay aware" in Beamer?

Code taken from Cancel maths expression with a down arrow

\documentclass{beamer}
\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},
strikee out/.style={shorten <=-.2em,shorten >=-.2em,overlay}
}
%
\newcommand{\cancel}[2][]{\tikz[baseline=(N.base)]{
  \node[main node](N){$#2$};
  \draw[strikee out,#1]  (N.south west) -- (N.north east);
}}
%
\begin{document}
%
\begin{frame}
\begin{align*}
a &= \frac{b}{c}\\
&= \frac{b}{b \cdot d}\\
\end{align*}
\end{frame}
%
%
\begin{frame}
\begin{align*}
a &= \frac{b}{c}\\
&= \frac{\cancel[red]{b}}{\cancel[red]{b} \cdot d}\\
\end{align*}
\end{frame}
%
\end{document}
5

I take that you want to cancel only on certain frames. If so, you might be looking for the overlay-beamer-styles library. You only need to add visible on=<...> for the cancel line being visible on the frames ....

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}
\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},
strikee out/.style={shorten <=-.2em,shorten >=-.2em,overlay}
}
%
\newcommand{\Cancel}[2][]{\tikz[baseline=(N.base)]{
  \node[main node](N){$#2$};
  \draw[strikee out,#1]  (N.south west) -- (N.north east);
}}
%
\begin{document}
%
%
\begin{frame}
\begin{align*}
a &= \frac{b}{c}\\
&= \frac{\Cancel[red,visible on=<2>]{b}}{\Cancel[red,visible on=<2>]{b} \cdot d}\\
\end{align*}
\end{frame}
%
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.