TransWikia.com

Does the tikz library `overlay-beamer-styles` support multiple fill colors?

TeX - LaTeX Asked on March 23, 2021

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

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

Answered by user228539 on March 23, 2021

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}

Answered by Zarko on March 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP