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

Manuel Schmidt
  • 3,537
  • 1
  • 19
  • 33

1 Answers1

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

  • Thx, but the result should look like the animation in my question. – Manuel Schmidt Jun 28 '18 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: – samcarter_is_at_topanswers.xyz Jun 28 '18 at 14:57
  • @samcarter Maybe you want to answer? (I am sorry for "stealing" the answer in the powerpoint question yesterday, I told the OP to accept your answer but (s)he wouldn't listen :-( –  Jun 28 '18 at 14:59
  • @marmot While I think that I understand the question, I have no idea how one would do that :) – samcarter_is_at_topanswers.xyz Jun 28 '18 at 15:02
  • @ManuelSchmidt I updated my answer after samcarter explained to me what the question is. Just to let you know that the downvote of your question did not come from me. –  Jun 28 '18 at 18:03
  • A big thanks to both of you. My question was not well written and I will try to make it clearer so others can understand it easier. – Manuel Schmidt Jun 29 '18 at 06:12
  • 2
    Glad the library is somehow useful for inspiration ;) – Claudio Fiandrino Jun 29 '18 at 06: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. ;-) –  Jun 29 '18 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:) – samcarter_is_at_topanswers.xyz Jun 29 '18 at 14:45
  • I'm trying to apply this solution but in my case the border of the spy in node disappears leaving the contents. Any hint? – Nicola Gigante Jan 26 '20 at 15:09