# how to align several tikzpicture displayed using \only

I a sequence of tikzpicture that are all similar but slightly different sizes (they have things that stick out. But I would like them all aligned at the same point of the tikzpicture.

I would have thought that setting a baseline for all of them would then align that coordinate point but they still "wiggle".

Here is a MWE. I want the open circle node at (0,0) to be in the same place on the page for each overlay. But it seems to center the bounding box for each tikzpicture; the size of the box changes because of the big green node. I though the baseline option would have accomplished this but it doesn't.

\documentclass{beamer}

\usepackage{tikz}

\begin{document}

\newcommand\grf[1]{
\begin{tikzpicture}%[baseline={(0,0)}]
\node[circle,draw] (0) at (0,0) {} ;  % <-- this circle node should not move
\node[circle,fill] (1) at (+1,+1) {} ;
\node[circle,fill] (2) at (+1,-1) {} ;
\node[circle,fill] (3) at (-1,-1) {} ;
\node[circle,fill] (4) at (-1,+1) {} ;
\node[circle,fill,green,inner sep=1em] at (#1) {} ;
\end{tikzpicture}
}

\begin{frame}
\only<1>{\grf{1}}%
\only<2>{\grf{2}}%
\only<3>{\grf{3}}%
\only<4>{\grf{4}}%
\end{frame}

\end{document}

• Possible duplicate of tex.stackexchange.com/questions/252860/… Mar 20 '20 at 14:45
• That seems to be about aligning frames. The first suggestion there is to use \begin[t]{frame}... \end{frame} which solves that issue, but not mine. IMHO my question is about when the pictures themselves are of different sizes, not when added text would move them around. But I've had the issue in that question as well and so already have [t] on my slides. Mar 20 '20 at 19:57

Setting the baseline does not avoid jumps in general since the bounding box still can change. One very quick fix is to exclude the extra node from the bounding box by adding the overlay key.

\documentclass{beamer}

\usepackage{tikz}
\begin{document}

\newcommand\grf[1]{
\begin{tikzpicture}%[baseline={(0,0)}]
\node[circle,draw] (0) at (0,0) {} ;  % <-- this circle node should not move
\node[circle,fill] (1) at (+1,+1) {} ;
\node[circle,fill] (2) at (+1,-1) {} ;
\node[circle,fill] (3) at (-1,-1) {} ;
\node[circle,fill] (4) at (-1,+1) {} ;
\node[circle,fill,green,inner sep=1em,overlay] at (#1) {} ;
\end{tikzpicture}
}

\begin{frame}
\only<1>{\grf{1}}%
\only<2>{\grf{2}}%
\only<3>{\grf{3}}%
\only<4>{\grf{4}}%
\end{frame}

\end{document}


In general, the TikZ library overlay-beamer-styles has many options to avoid jumps. Here you could use

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}

\begin{document}

\begin{frame}
\begin{tikzpicture}%[baseline={(0,0)}]
\node[circle,draw] (0) at (0,0) {} ;  % <-- this circle node should not move
\node[circle,fill] (1) at (+1,+1) {} ;
\node[circle,fill] (2) at (+1,-1) {} ;
\node[circle,fill] (3) at (-1,-1) {} ;
\node[circle,fill] (4) at (-1,+1) {} ;
\path foreach \X in {1,...,4}
{node[circle,fill,green,inner sep=1em,visible on=<\X>] at (\X) {} };
\end{tikzpicture}
\end{frame}

\end{document}


• that's exactly the kind of thing i was hoping for! Mar 20 '20 at 7:14
• thanks for the update; that's also very useful. if i could i'd accept your solution twice now! Mar 20 '20 at 19:51