Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to uncover a magnifying glass using the \spy functionality of TikZ, however, as you can see in the minimal working example below, the glass is there from frame 1. Does someone know how to fix this issue ?

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{shadows,spy,fixedpointarithmetic,patterns,arrows,decorations.text,decorations.pathmorphing,backgrounds,fit,positioning,shapes.symbols,chains}
\begin{document}

\begin{frame}
    Space
    \begin{center}
        \begin{tikzpicture}[spy scope={magnification=1.5, size=2cm},every spy in node/.style={remember picture,overlay,magnifying glass,circular drop shadow,fill=white,draw,ultra thick, cap=round}]
            \node[rectangle, draw, minimum width=1cm, minimum height=1cm] (N) {};
            \uncover<2->{\spy on (N) in node;}
            % \only<2>{\spy on (N) in node;}
        \end{tikzpicture}
    \end{center}
\end{frame}
\end{document}
share|improve this question
    
What's wrong with the only command you have commented out? –  Geoff Reedy Dec 26 '12 at 20:56
    
It's moving the text Space in the frame. –  BigDawg Dec 26 '12 at 21:08

1 Answer 1

up vote 8 down vote accepted

Why \uncover<2-> and \visible<2-> do not work I don’t know, but here are two work-arounds:

Work-Around 1: \alt + \pgfkeysalso

There are two /.styles and one /.code, to help with beamer:

  • invisible/.style={opacity=0,text opacity=0}
    This style is not very beamer special because it sets only every opacity (draw, fill, text) to zero, which means: It is there, but you cannot see it. It occupies the same space, much like \phantom.
  • alt/.code args={<#1>#2#3}{\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}}
    This code handler uses two things:

    1. The \alt<overlay>{arg1}{arg2} macro provided by beamer that executes arg1 when on overlay, otherwise arg2; and
    2. \pgfkeysalso which adds TikZ keys to a path without changing it otherwise. This is similar to adding [some keys=values] to a path.
  • visible on/.style={alt={#1{}{invisible}}}
    This style is rather a shortcut to alt. It does nothing to a path on <#1> but hides in otherwise.

If you want to use overlay specification with a ,, e.g. <2,4>, you have to enclose it in { }: visible on={<2,4>}. (For that same reason are the alt arguments enclosed in braces.)

Code

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shadows,spy,shapes.symbols}
\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} 
    },
}
\begin{document}

\begin{frame}
    Space
    \begin{center}
        \begin{tikzpicture}[spy scope={magnification=1.5, size=2cm},every spy in node/.style={remember picture,overlay,magnifying glass,circular drop shadow,fill=white,draw,ultra thick, cap=round}]
            \node[rectangle, draw, minimum width=1cm, minimum height=1cm] (N) {};
            \spy[visible on=<2->] on (N) in node;
        \end{tikzpicture}
    \end{center}
\end{frame}
\end{document}

Work-Around 2: overlay

The TikZ key overlay prevents the update of the bounding box. The content is simply overlayed on the page with no respect for everything.

This does work in this case …

Code

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shadows,spy,shapes.symbols}
\begin{document}

\begin{frame}
  Space
  \begin{center}
    \begin{tikzpicture}[spy scope={magnification=1.5, size=2cm},every spy in node/.style={remember picture,overlay,magnifying glass,circular drop shadow,fill=white,draw,ultra thick, cap=round}]
      \node[rectangle, draw, minimum width=1cm, minimum height=1cm] (N) {};
      \only<2->{\spy[overlay] on (N) in node;}
    \end{tikzpicture}
  \end{center}
\end{frame}
\end{document}
share|improve this answer
    
Thank you ! I tried the [overlay] option but with uncover, not only, of course I had the same issue, should have tried that in the first place instead of bothering you. Anyway your code for visible on might help me for some other things, so thanks again ! –  BigDawg Dec 27 '12 at 9:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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