3

The following presentation depicts an empty circle emerging on frame 2. The color of the circle then proceeds to toggle between blue and red.

enter image description here

This presentation was produced with the following code.

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}

\begin{document}

\begin{frame}{Frame \thepage}

  \[
    \begin{tikzpicture}

      \draw[
      , ultra thick
      , visible on=<{2,3,5}>
      , fill=blue
      , fill on=<{3,5}>
      ] circle (2cm);

      \draw[
      , ultra thick
      , visible on=<{4, 6}>
      , fill=red
      , fill on=<{4, 6}>
      ] circle (2cm);

    \end{tikzpicture}
  \]

\end{frame}

\end{document}

Here, the blue circles are defined separately from the red circles. I'm curious if it's possible to simplify this code by combining everything into one \draw command. I've tried doing

  \draw[
  , ultra thick
  , visible on=<{2-}>
  , fill=blue
  , fill on=<{3,5}>
  , fill=red
  , fill on=<{4, 6}>
  ] circle (2cm);

but this ignores all the blue circles:

enter image description here

Is there anything else I can do?

2 Answers 2

6

Yes, this is possible with the alt key (which derives from beamer's \alt command).

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}

\begin{document}

\begin{frame}{Frame \thepage}

  \[
    \begin{tikzpicture}

      \draw[
      , ultra thick
      , visible on=<{2-6}>
      ,alt=<{3,5}>{fill=blue}{fill=red,fill on=<{4, 6}>}
      ] circle[radius=2cm];

    \end{tikzpicture}
  \]

\end{frame}

\end{document}

enter image description here

4

One way is use preaction and postaction options:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}

\begin{document}
\begin{frame}{Frame \thepage}

    \[
\begin{tikzpicture}[ultra thick]
  \draw[preaction={fill=blue, visible on=<{3,5}>},
        visible on=<2->,
        postaction={fill=red, visible on=<{4,6}>}
       ] circle (2cm);
\end{tikzpicture}
    \]
\end{frame}

\end{document}

You must log in to answer this question.

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