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

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

1 Answer 1

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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .