2

In this example:

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
  \begin{overlayarea}{\linewidth}{0.7\paperheight}
    \centering
    \begin{tikzpicture}
      \coordinate (O) at (0, 0);
      \coordinate (A) at (5, 5);
      \coordinate (B) at (-5, 5);
      \only<1>
          {
            \draw (O) -- (B);
          }
          \only<2>
              {
                \draw (O) -- (B);
                \draw (O) -- (A);
              }
              \only<3>
                  {
                    \draw (O) -- (B);
                    \draw (O) -- (A);
                    \draw (A) -- (B);
                  }
    \end{tikzpicture}
  \end{overlayarea}
\end{frame}
\end{document}

I evolve an ever more complex picture over the slides:

enter image description here

However:

  1. in each slide I redraw everything that was drawn on the previous slide. How to carry over content from the previous slide?

  2. The line on slide 1 is displaced relative to the same line on the subsequent slides. How to enforce the same reference system on each slide.

1

The solution can be using \onslide:

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
    \centering
    \begin{tikzpicture}
      \coordinate (O) at (0, 0);
      \coordinate (A) at (5, 5);
      \coordinate (B) at (-5, 5);
\onslide<1->{
    \draw (O) -- (B);
    }
\onslide<2->{
    \draw (O) -- (A);
    }
\onslide<3->{
    \draw (A) -- (B);
    }
    \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

| improve this answer | |
3

overlay-beamer-styles is made for this. Unlike using \only, this generally avoids jumps without the need of adding a hard-coded bounding box the coordinates of which you need to guess and which you need to adjust if you decide to add paths later on.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}
\begin{document}
\begin{frame}
  \begin{overlayarea}{\linewidth}{0.7\paperheight}
    \centering
    \begin{tikzpicture}
      \coordinate (O) at (0, 0);
      \coordinate (A) at (5, 5);
      \coordinate (B) at (-5, 5);
      \draw (O) -- (B);
      \draw[visible on=<2->] (O) -- (A);
      \draw[visible on=<3->] (A) -- (B);
    \end{tikzpicture}
  \end{overlayarea}
\end{frame}
\end{document}

enter image description here

If you want the line joins to look good, maybe something like this is better. (In the present case you need to zoom in to see the difference, but in general this is better IMHO.)

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}
\begin{document}
\begin{frame}
  \begin{overlayarea}{\linewidth}{0.7\paperheight}
    \centering
    \begin{tikzpicture}
      \coordinate (O) at (0, 0);
      \coordinate (A) at (5, 5);
      \coordinate (B) at (-5, 5);
      \draw[visible on=<1>] (O) -- (B);
      \draw[visible on=<2>] (B) -- (O) -- (A);
      \draw[visible on=<3->] (B) -- (O) -- (A) -- cycle;
    \end{tikzpicture}
  \end{overlayarea}
\end{frame}
\end{document}

enter image description here

If you have many paths which you want to play with, you could define a style, accumulate path, that helps you accumulating these paths. You just draw these paths, and whenever you want that this and all following paths appear only on the next frame, you need to add vis+. You do not need any scopes or anything, just vis+.

\documentclass{beamer}
\usepackage{tikz}
\newcounter{Viesturs-step}
\resetcounteronoverlays{Viesturs-step}%
\usetikzlibrary{overlay-beamer-styles}
\tikzset{accumulate path/.style={/utils/exec=\setcounter{Viesturs-step}{#1},
every path/.append style={visible on=<\number\value{Viesturs-step}->}},
accumulate path/.default=1,
vis+/.style={/utils/exec=\stepcounter{Viesturs-step},
visible on=<\number\value{Viesturs-step}->}}
\begin{document}
\begin{frame}[t]
    \centering
    \begin{tikzpicture}[accumulate path]
      \coordinate (O) at (0, 0);
      \coordinate (A) at (5, 5);
      \coordinate (B) at (-5, 5);
      \draw (O) -- (B);
      \draw[red] (O) to[bend left] (B);
      \draw[vis+] (O) -- (A);
      \draw[red] (O)  to[bend right]  (A);
      \draw[vis+] (A) -- (B);
      \draw[red] (A)  to[bend right]  (B);
    \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

| improve this answer | |
2
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
  \begin{overlayarea}{\linewidth}{0.7\paperheight}
    \centering
    \begin{tikzpicture}
    \useasboundingbox(-5.5,-.5)rectangle(6,5.5);% 
      \coordinate (O) at (0, 0);
      \coordinate (A) at (5, 5);
      \coordinate (B) at (-5, 5);

            \draw<1-> (O) -- (B);
            \draw<2-> (O) -- (A);
            \draw<3> (A) -- (B);
    \end{tikzpicture}
  \end{overlayarea}
\end{frame}
\end{document}

screenshot

| improve this answer | |
  • What if I drew 10 new lines on each slide? Can I group these objects and add <1-> to this group instead of adding to each object separately? – Viesturs Nov 29 '19 at 16:46
  • @Viesturs simply put it on a scope environment \begin{scope}<1-> \draw (O) -- (B); \draw(O)to[bend left](B); \end{scope} – AndréC Nov 29 '19 at 16:49
  • In case I use scope to group elements also on the last slide, the slide show collapses to the last slide - tex.stackexchange.com/questions/518776/… – Viesturs Dec 1 '19 at 10:16
  • I experience trouble when applying the <> slide specifier to a newcommand tex.stackexchange.com/questions/518782/… – Viesturs Dec 1 '19 at 11:26

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.