3

Using the spy library, I would like to first highlight (in this case with an rectangle) the area which gets magnified and the show the magnification on the next slide. I am doing this manually in the MWE below, but prefer an automatic solution.

\documentclass[10pt,aspectratio=169]{beamer}

\usepackage{tikz}
\usetikzlibrary{spy}

\begin{document}
\begin{frame}
\begin{tikzpicture}[%
   spy using outlines={rectangle, magnification=4, size=2cm, connect spies},
]
    \fill [blue!20] (0,0) rectangle (2,3);
    % I want to avoid to manually draw this rectangle:
    \draw (-2.5mm,-2.5mm) rectangle (2.5mm, 2.5mm); 
    \pause
    \spy on (0,0) in node at (-2,1);

\end{tikzpicture}
\end{frame}
\end{document}

The result should look like this: enter image description here

0

1 Answer 1

5

Big thanks to @samcarter for explaining the question to me! Using some tricks from the aobs package.

\documentclass[10pt,aspectratio=169]{beamer}

\usepackage{tikz}
\usetikzlibrary{spy}
\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    connect on/.style={alt={#1{connect spies}{}}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} 
    },
}

\begin{document}
\begin{frame}
\begin{tikzpicture}[%
   spy using outlines={rectangle, magnification=4, size=2cm},
]
    \fill [blue!20] (0,0) rectangle (2,3);
    \spy[connect on=<2->] on (0,0) in node[visible on=<2->] at (-2,1);

\end{tikzpicture}
\end{frame}
\end{document}

enter image description here

10
  • Thx, but the result should look like the animation in my question. Commented Jun 28, 2018 at 11:30
  • @marmot At first I did not understand the question at all, but after a while I think the key of the question is hidden in the comment % I want to avoid to manually draw this rectangle: Commented Jun 28, 2018 at 14:57
  • 2
    Glad the library is somehow useful for inspiration ;) Commented Jun 29, 2018 at 6:41
  • 1
    @ClaudioFiandrino The library is great!! Sadly, some excerpts from it are scattered over the places without mentioning the source. (So I tried to do better, e.g. here. ;-)
    – user121799
    Commented Jun 29, 2018 at 14:01
  • 2
    @ClaudioFiandrino The library is fantastic! Thanks a lot for it! The only problem is that I can never remember the order of the letters in aobs:) Commented Jun 29, 2018 at 14:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .