4

I have written the following code to construct a slide in beamer. I would like the graph in the tikzpicture in the right column to be visible since the beginning of the slide, except for the rounded blue rectangles I define inside the tikzpicture, which should appear at the second step. Moreover, what I achieved so far "moves" the graph when those rectangles are displayed (going from step 1 to step 2): that should not happen!

Could you help me?

\documentclass[10pt,xcolor={dvipsnames}]{beamer}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{tikz}

\mode<presentation>{
    \usetheme{Frankfurt}
    \useinnertheme{default}
    \useoutertheme{default}
    \usecolortheme{default}
    \setbeamercovered{transparent}
    \setbeamercolor{block body example}{fg=black,bg=Blue!10}
    \setbeamercolor{postit}{fg=black,bg=OliveGreen!20}
    \setbeamercolor{postit2}{fg=yellow,bg=OliveGreen}
}

\setbeamersize{text margin left=2em, text margin right=2em}

\begin{document}
\begin{frame}{TITLE}
    \begin{columns}[c]
        \begin{column}{.75\textwidth}
        The black graph should already be visible...\\
        \smallskip
        \pause
        Here the blue rectangles should appear and remain visible until the end...\\
        \smallskip
        \pause
        Line 3...\\
        \smallskip
        \pause
        Line 4...\\
        \end{column}
        \begin{column}{.2\textwidth}
           \visible<1->{
            \begin{tikzpicture}[scale=.8,vertex/.style={
    circle,fill=black,minimum size=5pt,inner sep=0pt}]
                %% vertices
                \node[vertex] (V1) at (0,0) {};
                \node[vertex] (V2) at (.5,1) {};
                \node[vertex] (V3) at (1.5,1.5) {};
                \node[vertex] (V4) at (1,.5) {};
                \node[vertex] (V5) at (1,-1) {};
                \node[vertex] (V6) at (.75,-2) {};
                \node[vertex] (V7) at (1.25,-2) {};
                \node[vertex] (V8) at (-.75,-.75) {};
                %% vertex labels
                \node at (-.25,.25) {$a_1$};
                %% edges
                \draw[dashed] (.25,1.75) -- (V2) -- (.75,1.75);
                \draw[dashed] (1.75,.75) -- (V4) -- (1.75,.25);
                \draw[dashed] (V6) -- (.75,-2.5);
                \draw[dashed] (V7) -- (1.25,-2.5);
                \foreach \from/\to in {V1/V2,V2/V3,V3/V4,V4/V1,V1/V5,V5/V6,V5/V7,V1/V8}
                   \draw[thick] (\from) -- (\to);
               %% connected components
               \draw<2->[blue,thick,rounded corners] (.15,.15) rectangle (1.9,1.9) {};
               \draw<2->[blue,thick,rounded corners] (-1.25,-1.25) rectangle (-.25,-.25);
               \draw<2->[blue,thick,rounded corners] (.5,-3) rectangle (1.5,-.5);
            \end{tikzpicture}
            }
        \end{column}
    \end{columns}
\end{frame}
\end{document}
  • 1
    Please, give a fully compileable code. – AndréC Dec 11 '19 at 20:27
  • I updated my question. – Sirion Dec 11 '19 at 20:37
  • Once the rectangles are displayed, should they remain displayed afterwards or not? – AndréC Dec 11 '19 at 20:41
  • Yes, they should remain until the end of the slide. – Sirion Dec 11 '19 at 20:42
7

I wonder if this is the expected behaviour in beamer because I think that to get what you want it should be enough to surround the relevant code with \uncover<1->{...} etc but this does not work for me. The problem seems to be the previous \pause commands, but I am sure that I have done this before. Perhaps the columns environment is getting in the way?

Whether this is the intended behaviour or not, you can get around this issue by "resetting" the pause counter by inserting \pause[0] before the tikzpicture environment. Once you do this \uncover... works as expected to produce:

enter image description here

As shown, if you have material after the tikzpicture environment that you want to incrementally display then you need to add \pause[5] to resynchronize the pause counter.

Here is the full code:

\documentclass[10pt,xcolor={dvipsnames}]{beamer}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{tikz}

\mode<presentation>{
    \usetheme{Frankfurt}
    \useinnertheme{default}
    \useoutertheme{default}
    \usecolortheme{default}
    \setbeamercovered{transparent}
    \setbeamercolor{block body example}{fg=black,bg=Blue!10}
    \setbeamercolor{postit}{fg=black,bg=OliveGreen!20}
    \setbeamercolor{postit2}{fg=yellow,bg=OliveGreen}
}

\setbeamersize{text margin left=2em, text margin right=2em}

\begin{document}
\begin{frame}{TITLE}
    \begin{columns}[c]
        \begin{column}{.75\textwidth}
        The black graph should already be visible...\\
        \smallskip
        \pause
        Here the blue rectangles should appear and remain visible until the end...\\
        \smallskip
        \pause
        Line 3...\\
        \smallskip
        \pause
        Line 4...\\
        \end{column}
        \pause[0]
        \begin{column}{.2\textwidth}
            \begin{tikzpicture}[scale=.8,vertex/.style={
    circle,fill=black,minimum size=5pt,inner sep=0pt}]
                %% vertices
                \uncover<1->{
                  \node[vertex] (V1) at (0,0) {};
                  \node[vertex] (V2) at (.5,1) {};
                  \node[vertex] (V3) at (1.5,1.5) {};
                  \node[vertex] (V4) at (1,.5) {};
                  \node[vertex] (V5) at (1,-1) {};
                  \node[vertex] (V6) at (.75,-2) {};
                  \node[vertex] (V7) at (1.25,-2) {};
                  \node[vertex] (V8) at (-.75,-.75) {};
                  %% vertex labels
                  \node at (-.25,.25) {$a_1$};
                  %% edges
                  \draw[dashed] (.25,1.75) -- (V2) -- (.75,1.75);
                  \draw[dashed] (1.75,.75) -- (V4) -- (1.75,.25);
                  \draw[dashed] (V6) -- (.75,-2.5);
                  \draw[dashed] (V7) -- (1.25,-2.5);
                  \foreach \from/\to in {V1/V2,V2/V3,V3/V4,V4/V1,V1/V5,V5/V6,V5/V7,V1/V8}
                     \draw[thick] (\from) -- (\to);
                }
               %% connected components
               \uncover<2->{
                 \draw[blue,thick,rounded corners] (.15,.15) rectangle (1.9,1.9) {};
                 \draw[blue,thick,rounded corners] (-1.25,-1.25) rectangle (-.25,-.25);
                 \draw[blue,thick,rounded corners] (.5,-3) rectangle (1.5,-.5);
               }
            \end{tikzpicture}
        \end{column}
    \end{columns}
    \pause[5]
    Some stuff at the end
\end{frame}
\end{document}
  • Thank you! Is there a way to avoid the shift of the image when the blue rectangles appear? – Sirion Dec 11 '19 at 21:20
  • @Sirion Sorry, didn't notice that. Use \uncover instead of \only. I'll edit. – Andrew Dec 11 '19 at 21:25

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.