3

In the following MWE:

\documentclass{beamer}
\setbeamertemplate{footline}[page number]
\usepackage{tikz}
\usetikzlibrary{spy,shadows,decorations.fractals}
\begin{document}
\begin{frame}
\begin{tikzpicture}
  [spy scope={magnification=4, size=1cm},
  every spy in node/.style={%
    drop shadow,
    fill=white,
    draw,
  }]
  \draw [decoration=Koch curve type 2]
  decorate{ decorate{ decorate{ (0,0) -- (2,0) }}};
  \only<2>{\spy on (0,0) in node;}
\end{tikzpicture}
\end{frame}
\end{document}

the main tikz picture on the 2nd frame is right shifted because of the \spy node, the size of which being non zero.

enter image description here

But I'd like the main picture to stay static, even if the \spy node partially vanishes in the left margin.

I guess this could be done by making the \spy node's size null in order it is not taken in account. How could I achieve such a result?

Denis Bitouzé
  • 9,652
  • 4
  • 27
  • 85
  • 2
    Just draw the \spy "always", but invisible when not wanted. Thereby the tikzpicture always keeps the same size. Look at this answer for a general solution. – Daniel Sep 09 '16 at 22:00
  • @Daniel It could be an option but, in my real use case, the main picture is quite large (in order it is easily read), hence I'd prefer it fills the text width even if the magnified parts are partially hidden. – Denis Bitouzé Sep 10 '16 at 08:37

1 Answers1

6

Put the picture flushright into a container that is at least as wide as the widest picture, then the picture will stay in place; like this:

\makebox[4cm][r]{%
\begin{tikzpicture}

...

\end{tikzpicture}%
}

A more general solution, in case your picture changes its size in all directions: draw a bounding box that contains all parts of the picture, in every frame. In your example, put the line

\draw[use as bounding box] (-0.51,-0.7) rectangle (2,0.7);

into your tikzpicture. As soon as you are satisfied with the size of the box, replace \draw by \path, et voilà!

enter image description here

Yet another solution, if you definitely want that the spies overlap with surrounding text: add the overlay keyword, like this:

\only<2>{\spy[overlay] on (0,0) in node;}
\only<3>{\spy[overlay] on (2,0) in node;}
\only<4>{\spy[overlay] on (1,0.5) in node;}
\only<5>{\spy[overlay] on (1,-0.5) in node;}

With some text around it, it looks like this:

enter image description here

gernot
  • 49,614
  • Your 1st solution is quite nice but isn't appropriate to my real use case as there will be magnified parts of my main picture at several places (left side, center, right side). AFAICS, your 2nd solution is of the same kind as the one suggested in Daniel's comment, and isn't appropriate either. Because there will be magnified parts of my main picture at several places, I'd like the \spy nodes to have zero size, as if they were in a \makebox[0pt][l]{...}. – Denis Bitouzé Sep 10 '16 at 09:04
  • You are really a demanding customer, never satisfied ;-) I have added another solution using the overlay keyword. Now tikz ignores the spy when computing the bounding box, so it will cover surrounding material when it appears. Is this more like what you want? – gernot Sep 10 '16 at 10:33
  • Well, I really wanted to accept your answer but the 1st ones didn't answer my question, hence I helped you to provide the right one ;) That's definitively what I was looking for! :) – Denis Bitouzé Sep 11 '16 at 07:41