0

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}
\item This page has 3 lines
\item This page has 3 lines
\item This page has 3 lines
\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}
\item This page has 2 lines
\item This page has 2 lines
\end{itemize}
\end{frame} 

\end{document}

enter image description here

  • 1
    Do you want the dashed line and both squares (with different sizes) in a fixed position? – Sigur Jun 3 '18 at 19:05
  • 1
    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. – user121799 Jun 3 '18 at 19:08
  • 1
    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
  • 1
    @csss, to fill both squares, use only \fill[black] ... – Sigur Jun 3 '18 at 19:16
  • 1
    @csss, did you use [t] on frames as suggested? It is working here. – Sigur Jun 3 '18 at 19:20
3

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}
        \item This page has 3 lines
        \item This page has 3 lines
        \item This page has 3 lines
    \end{itemize}
}
\only<2>{
    \begin{itemize}
        \item This page has 2 lines
        \item This page has 2 lines
    \end{itemize}
}
\end{frame}  

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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