# Tikz picture object changes size on each beamer frame and causes picture and text positions to shift?

I am creating a beamer presentation with several slides that features a tikz picture above an item list. Because one of the objects changes size in the text picture on each slide, the text and the tikz picture shift position as I change slides. How can I keep the position of the text and the tikz picture fixed for all slides? I have attached an image of the problem and some tex code demonstrating it.

\documentclass{beamer}

\usepackage{tikz}

\begin{document}

\begin{frame}[t]
\footnotesize
\begin{tikzpicture}
\def\wl{2}
\def\wh{0.8}
\def\posx{210}
\begin{scope}[xshift=-50]
\draw[black,dashed] (0,0) --  (pi*\wl,0);
\end{scope}

\begin{scope}[xshift=\posx,scale=1,transform shape]
\fill[black] (-2,-2) rectangle ++(4,4);
\end{scope}
\end{tikzpicture}
\begin{itemize}
\end{itemize}
\end{frame}

\begin{frame}[t]
\footnotesize
\begin{tikzpicture}
\path (-2,-2) rectangle ++(4,4);
\def\wl{2}
\def\wh{0.8}
\def\posx{210}
\begin{scope}[xshift=-50]
\draw[black,dashed] (0,0) --  (pi*\wl,0);
\end{scope}

\begin{scope}[xshift=\posx,scale=1,transform shape]
\fill[black] (-1,-1) rectangle ++(2,2);
\end{scope}
\end{tikzpicture}
\begin{itemize}
\end{itemize}
\end{frame}

\end{document}


• Do you want the dashed line and both squares (with different sizes) in a fixed position? – Sigur Jun 3 '18 at 19:05
• If you use \begin{frame}[t] instead of \begin{frame} the slides won't jump but of course if the pictures have different heights the texts will move. – marmot Jun 3 '18 at 19:08
• You can use a transparent path just to make sure both figures have the same height. Use \path (-2,-2) rectangle ++(4,4); in the second figure and don't draw in the first, only fill it, to avoid different strokes. – Sigur Jun 3 '18 at 19:11
• @csss, to fill both squares, use only \fill[black] ...  – Sigur Jun 3 '18 at 19:16
• @csss, did you use [t] on frames as suggested? It is working here. – Sigur Jun 3 '18 at 19:20

Here is a shorter code, using [t] as frame option (suggested by @marmot), and faking a path on second slide with same size as the square from the first slide.

Also, using overlay specification, we can write everything inside a single frame.

\documentclass{beamer}
\usepackage{tikz}

\begin{document}

\begin{frame}[t]
\footnotesize

\begin{tikzpicture}
\def\wl{2}
\def\wh{0.8}
\def\posx{210}

\begin{scope}[xshift=-50]
\draw[black,dashed] (0,0) --  (pi*\wl,0);
\end{scope}

\uncover<1>{
\begin{scope}[xshift=\posx,scale=1,transform shape]
\fill[black] (-2,-2) rectangle ++(4,4);
\end{scope}
}
\uncover<2>{
\begin{scope}[xshift=\posx,scale=1,transform shape]
\fill[black] (-1,-1) rectangle ++(2,2);
\path (-2,-2) rectangle ++(4,4);  %  <-- transparent path
\end{scope}
}

\end{tikzpicture}

\only<1>{
\begin{itemize}