3

I have two images drawn in TikZ that I want shown one element at a time. Specifically, I want the circle on the left first, then the ellipses around it. Then I want the circle on the right followed by the ellipses around it. I tried using \pause, \only, \visible, and whatever else I could find only, but I can't get it working (I get compilation errors with all above commands).

\documentclass{beamer}
\mode<presentation>
{
%  \usetheme{default}      % or try Darmstadt, Madrid, Warsaw, ...
%  \usecolortheme{default} % or try albatross, beaver, crane, ...
%  \usefonttheme{default}  % or try serif, structurebold, ...
  \setbeamertemplate{navigation symbols}{}
  \setbeamertemplate{caption}[numbered]
}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{verbatim}
\usepackage{tikz}
\usetikzlibrary{arrows, arrows.meta, 
                backgrounds,
                calc,
                decorations.pathmorphing,
                patterns, positioning, 
                quotes,
                shapes,
                tikzmark
                }
%\tikzstyle{every picture}+=[remember picture, overlay]
\usetikzlibrary{overlay-beamer-styles}
\usepackage{tcolorbox}
\tcbuselibrary{raster}
\tcbuselibrary{theorems}
\usepackage{makecell} %for the thead command to break up header
%\usepackage{fourier,erewhon}
%\usepackage{amssymb, amsbsy}
\usepackage{array, booktabs, longtable}
\usepackage{graphicx}
%\usepackage[x11names, table]{xcolor}
\usepackage{caption}


%% start
\begin{document}


\section{Problem Setup, History, \& Our Result: A Snapshot}

\begin{frame}[t]{Def} 
    \newtcbtheorem[number within = section]{mydef}{Problem Statement}{colback=orange!20, colframe=blue!25}{ps}
    \tcbset{colframe=red!75!black, colback=yellow!25!white}             

    \begin{mydef}{Definition}{probStatement}
        Given stuff, prove: 
        \begin{equation*}
        \tcboxmath[colframe=red!75!black, colback=yellow!25!white]
        {a + b = c}
        \end{equation*}
    \end{mydef}
    \begin{tikzpicture}
        \coordinate (c) at (2.2, -0.2); 
        \draw[black, thick](c) circle (50 pt);
        \draw[black, fill = green!10, rotate = 50, opacity = 0.25] (c) ellipse (60 pt and 10 pt);
        \draw[black, fill = red!10, rotate = 30, opacity = 0.25] (c) ellipse (20 pt and 10 pt);
        \draw[black, fill = blue!10, rotate = 100, opacity = 0.25] (c) ellipse (25 pt and 45 pt);
        \draw[black, fill = teal!20, rotate = 110, opacity = 0.25] (c) ellipse (35 pt and 70 pt);
        \draw[black, fill = magenta!30, rotate = 240, opacity = 0.25] (c) ellipse (45 pt and 65 pt);

        \coordinate (cCovering) at (8.5, -0.2); 
        \draw[black, thick](cCovering) circle (50 pt);
        \draw[black, fill = red!10, rotate = 30, opacity = 0.25] (cCovering) ellipse (20 pt and 10 pt);
        \draw[black, fill = blue!10, rotate = 100, opacity = 0.25] (cCovering) ellipse (25 pt and 45 pt);
        \draw[black, fill = green!10, rotate = 50, opacity = 0.25] (cCovering) ellipse (10 pt and 30 pt);
        \draw[black, fill = teal!20, rotate = 50, opacity = 0.25] (cCovering) ellipse (75 pt and 20 pt);
        \draw[black, fill = gray!30, rotate = 280, opacity = 0.25] (cCovering) ellipse (45 pt and 65 pt);
    \end{tikzpicture}
\end{frame}
\end{document}

lazulikid
  • 561

2 Answers2

4

There are two problems: first of all, when you define a new theorem in a slide with breaks, this causes problems. The perhaps simplest fix is to move

\newtcbtheorem[number within = section,reset counter on overlays]{mydef}{Problem Statement}{colback=orange!20, colframe=blue!25}{ps}

before the slide. Note the reset counter on overlays which avoids that the counters increase after each break. Then you can use \uncover or visible on from the overlay-beamer-styles library. However, the latter works by setting the opacity to 0, and since you set it explicitly for the ellipses you may want to use uncover for those.

\documentclass{beamer}
\mode<presentation>
{
%  \usetheme{default}      % or try Darmstadt, Madrid, Warsaw, ...
%  \usecolortheme{default} % or try albatross, beaver, crane, ...
%  \usefonttheme{default}  % or try serif, structurebold, ...
  \setbeamertemplate{navigation symbols}{}
  \setbeamertemplate{caption}[numbered]
}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{verbatim}
\usepackage{tikz}
\usetikzlibrary{arrows, arrows.meta, 
                backgrounds,
                calc,
                decorations.pathmorphing,
                patterns, positioning, 
                quotes,
                shapes,
                tikzmark
                }
\usetikzlibrary{overlay-beamer-styles}
\usepackage{tcolorbox}
\tcbuselibrary{raster}
\tcbuselibrary{theorems}
\usepackage{makecell} %for the thead command to break up header
%\usepackage{fourier,erewhon}
%\usepackage{amssymb, amsbsy}
\usepackage{array, booktabs, longtable}
\usepackage{graphicx}
%\usepackage[x11names, table]{xcolor}
\usepackage{caption}


%% start
\newtcbtheorem[number within = section,reset counter on overlays]{mydef}{Problem Statement}{colback=orange!20, colframe=blue!25}{ps}
\begin{document}


\section{Problem Setup, History, \& Our Result: A Snapshot}

\begin{frame}[t]
\frametitle{Def} 
    \tcbset{colframe=red!75!black, colback=yellow!25!white}             
    \begin{mydef}{Definition}{probStatement}
        Given stuff, prove: 
        \begin{equation*}
        \tcboxmath[colframe=red!75!black, colback=yellow!25!white]
        {a + b = c}
        \end{equation*}
    \end{mydef}
    \begin{tikzpicture}
        \coordinate (c) at (2.2, -0.2); 
        \draw[black, thick](c) circle (50 pt);
        \uncover<2->{
          \draw[black, fill = green!10, rotate = 50, opacity = 0.25] (c) ellipse (60 pt and 10 pt);
          \draw[black, fill = red!10, rotate = 30, opacity = 0.25] (c) ellipse (20 pt and 10 pt);
          \draw[black, fill = blue!10, rotate = 100, opacity = 0.25] (c) ellipse (25 pt and 45 pt);
          \draw[black, fill = teal!20, rotate = 110, opacity = 0.25] (c) ellipse (35 pt and 70 pt);
          \draw[black, fill = magenta!30, rotate = 240, opacity = 0.25] (c) ellipse (45 pt and 65 pt);
        }

        \coordinate (cCovering) at (8, -0.2); 
        \draw[black, thick,visible on=<3->](cCovering) circle (50 pt);
        \uncover<4->{
          \draw[black, fill = red!10, rotate = 30, opacity = 0.25] (cCovering) ellipse (20 pt and 10 pt);
          \draw[black, fill = blue!10, rotate = 100, opacity = 0.25] (cCovering) ellipse (25 pt and 45 pt);
          \draw[black, fill = green!10, rotate = 50, opacity = 0.25] (cCovering) ellipse (10 pt and 30 pt);
          \draw[black, fill = teal!20, rotate = 50, opacity = 0.25] (cCovering) ellipse (75 pt and 20 pt);
          \draw[black, fill = gray!30, rotate = 280, opacity = 0.25] (cCovering) ellipse (45 pt and 65 pt);
         }
    \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

  • Thank you, Schrodinger's cat (btw, I LOVE the username :)) I have two follow up questions on your solution, if that's alright: First, why does the mere change of moving the definition of newtheorem outside the slide fix it? It's such a counterintuitive fix (to me), I could never come up with it, hence I ask. Second, thank you for your solution -- however, there seems to be an issue, wherein the numbering of the problem statement increments as the ellipses uncover - do you think you could get rid of that? Maybe moving the definition out caused this? Again, thanks so much! – lazulikid May 17 '20 at 05:59
  • 2
    @lazulikid As for the first question, you cannot easily have definitions with #1 and so on in a beamer frame with breaks. These definitions are hidden in \newtcbtheorem. One can allow for them by making the frame fragile, but it is arguably simpler/better to move them out. As for 2, good catch, my bad, we need reset counter on overlays. –  May 17 '20 at 06:20
  • Thank you once again, Schrodinger's cat! I found a compiler error using "reset counter on overlays", but after some quick googling found a command in the same spirit that works for me. In particular (for anyone else who ends up on this question), the fix I found was to use "\resetcounteronoverlays{tcb@cnt@mydef}" right after the newtcbtheorem command (outside the slide). – lazulikid May 17 '20 at 18:30
  • 1
    @lazulikid The reset counter on overlays key is part of the newer versions of tcolorbox. It has has been added after this thread, see this issue. ;-) –  May 17 '20 at 18:52
3

I found that the following code work:

\documentclass{beamer}
\mode<presentation>
{
%  \usetheme{default}      % or try Darmstadt, Madrid, Warsaw, ...
%  \usecolortheme{default} % or try albatross, beaver, crane, ...
%  \usefonttheme{default}  % or try serif, structurebold, ...
  \setbeamertemplate{navigation symbols}{}
  \setbeamertemplate{caption}[numbered]
}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{verbatim}
\usepackage{tikz}
\usetikzlibrary{arrows, arrows.meta, 
                backgrounds,
                calc,
                decorations.pathmorphing,
                patterns, positioning, 
                quotes,
                shapes,
                tikzmark
                }
%\tikzstyle{every picture}+=[remember picture, overlay]
\usetikzlibrary{overlay-beamer-styles}
\usepackage{tcolorbox}
\tcbuselibrary{raster}
\tcbuselibrary{theorems}
\newtcbtheorem[number within = section]{mydef}{Problem Statement}{colback=orange!20, colframe=blue!25}{ps}
\tcbset{colframe=red!75!black, colback=yellow!25!white}  
\usepackage{makecell} %for the thead command to break up header
%\usepackage{fourier,erewhon}
%\usepackage{amssymb, amsbsy}
\usepackage{array, booktabs, longtable}
\usepackage{graphicx}
%\usepackage[x11names, table]{xcolor}
\usepackage{caption}


%% start
\begin{document}


\section{Problem Setup, History, \& Our Result: A Snapshot}

\begin{frame}[t]{Def}            

    \begin{mydef}{Definition}{probStatement}
        Given stuff, prove: 
        \begin{equation*}
        \tcboxmath[colframe=red!75!black, colback=yellow!25!white]
        {a + b = c}
        \end{equation*}
    \end{mydef}
    \begin{tikzpicture}
        \coordinate (c) at (2.2, -0.2);
\onslide<1->{
        \draw[black, thick](c) circle (50 pt);
    }
\onslide<2->{
        \draw[black, fill = green!10, rotate = 50, opacity = 0.25] (c) ellipse (60 pt and 10 pt);

        \draw[black, fill = red!10, rotate = 30, opacity = 0.25] (c) ellipse (20 pt and 10 pt);
        \draw[black, fill = blue!10, rotate = 100, opacity = 0.25] (c) ellipse (25 pt and 45 pt);
        \draw[black, fill = teal!20, rotate = 110, opacity = 0.25] (c) ellipse (35 pt and 70 pt);
        \draw[black, fill = magenta!30, rotate = 240, opacity = 0.25] (c) ellipse (45 pt and 65 pt);
}
        \coordinate (cCovering) at (8.5, -0.2);
\onslide<3->{
        \draw[black, thick](cCovering) circle (50 pt);
    }
\onslide<4->{
        \draw[black, fill = red!10, rotate = 30, opacity = 0.25] (cCovering) ellipse (20 pt and 10 pt);
        \draw[black, fill = blue!10, rotate = 100, opacity = 0.25] (cCovering) ellipse (25 pt and 45 pt);
        \draw[black, fill = green!10, rotate = 50, opacity = 0.25] (cCovering) ellipse (10 pt and 30 pt);
        \draw[black, fill = teal!20, rotate = 50, opacity = 0.25] (cCovering) ellipse (75 pt and 20 pt);
        \draw[black, fill = gray!30, rotate = 280, opacity = 0.25] (cCovering) ellipse (45 pt and 65 pt);
    }
    \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

vi pa
  • 3,394