7

I wonder how to get automated continuing example counters in Beamer. Below is my MWE. Thanks for your help.

\documentclass{beamer}
\usetheme{Warsaw}


\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]

\begin{document}

\begin{frame}
  \begin{example}
  This is a test example
   \end{example}
\end{frame}

\begin{frame}
  \setcounter{example}{2}
  \begin{example}
   Continued  previous example.
  \end{example}
\end{frame}

\end{document}

UPDATE

I'm looking automated continuation of example counter like this one Continuing enumerate Counters in Beamer. Thanks

  • 2
    Remove the line \setcounter{example}{2}. Everything should work fine. – A.Ellett Jul 7 '13 at 21:05
  • 1
    Thanks @A.Ellett for your comment. Following your suggestion I will get Example 1.1 on frame 1 and Example 1.2 on frame 2. But I need Example 1.1 on both frames automatically. Thanks – MYaseen208 Jul 10 '13 at 15:50
8
+50

Define a "continuation example" environment:

\documentclass{beamer}
\usetheme{Warsaw}

\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]
\newenvironment{example*}
  {\addtocounter{theorem}{-1}\example}
  {\endexample}

\begin{document}

\begin{frame}
  \begin{example}
  This is a test example
   \end{example}
\end{frame}

\begin{frame}
  \begin{example*}
   Continued  previous example.
  \end{example*}
\end{frame}

\begin{frame}
  \begin{example*}
   Continued  previous example.
  \end{example*}

  \begin{example}
   New example.
  \end{example}
\end{frame}

\end{document}

enter image description here

  • 2
    Could you please point out why for this particular environment (example), \theexample or \value{example} works fine, but whenever we try to manipulate the example counter, e.g., \addtocounter{example}{-1}, the counter is termed as undefined. – Masroor Jul 10 '13 at 21:34
  • 1
    @MMA There is no example counter and \theexample expands to \thetheorem. – egreg Jul 10 '13 at 21:46
  • 1
    Indeed, if I have an example environment, followed by a `theorem' environment, the later is numbered $n+1$, where, $n$ is the number of the first one. Any way to keep these independent? – Masroor Jul 10 '13 at 21:53
  • You can define new theorems with \newtheorem, see section 12.4 in the documentation. – egreg Jul 10 '13 at 21:59
4

The following is a mild generalization of egreg's answer that allows for "continuing examples" mixed inbetween the regular flow of examples. I'm not convinced that this is a valid use-case, since continued examples will typically follow one another from one slide/frame to the next, but it may serve some purpose in a bigger context:

enter image description here

\documentclass{beamer}% http://ctan.org/pkg/beamer
\usetheme{Warsaw}
\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]
\makeatletter
\def\@firstoffive#1#2#3#4#5{#1}%
\newenvironment{example*}[1][\relax]
  {\begingroup\ifx#1\relax% No optional argument
   \else% Optional argument given
     \@ifundefined{r@#1}{}{%
       \protected@edef\cont@example@num{\csname r@#1\endcsname}%
       \expandafter\edef\expandafter\cont@example@num\expandafter
         {\expandafter\@firstoffive\cont@example@num}%%
       \renewcommand{\thetheorem}{\cont@example@num}}%
   \fi\addtocounter{theorem}{-1}% Revert to previous theorem count
   \example}
  {\endexample\endgroup}
\makeatother
\begin{document}

\begin{frame}
  \begin{example}
    This is a test example.
  \end{example}

  \begin{example*}
    This one continues.
  \end{example*}

  \begin{example}
    Another example.\label{myexample}
  \end{example}
\end{frame}

\begin{frame}
  \begin{example}
    This is a test example.
  \end{example}

  \begin{example*}[myexample]
    Continued previous example.
  \end{example*}

  \begin{example}
    Another new example.
  \end{example}
\end{frame}

\end{document}

The continued example environment example* now comes with an optional argument that should contain a reference to a \label set in the example that should be continued. If no argument is given, example* acts as expected and continues the previous example.

3

Try overlays:

\documentclass{beamer}
\usetheme{Warsaw}


\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]

\begin{document}

\begin{frame}
\only<1>{  \begin{example}
  This is a test example
   \end{example}
}
\only<2>{
  \begin{example}
   Continued  previous example.
  \end{example}}
  \begin{example}
   Another  previous example.
  \end{example}
\end{frame}
\begin{frame}
  \begin{example}
   Another  previous example.
  \end{example}
\end{frame}
\end{document}

Only I can can't see 1.1 but 1 as you stated in the comments. So you possibly used another code?

No. 2

Saves counter, and sets counter to the saved value. Usage: smyex is the parent while emyex is the child which has the same number, until the next use of smyex . Hope this is what you understand under automation.

\documentclass{beamer}
\usetheme{Warsaw}


\setbeamertemplate{theorem}[ams style]
\setbeamertemplate{theorems}[numbered]
\newcounter{extemp}
\newcounter{restoretemp}



\newenvironment{smyex}{\setcounter{extemp}{\theexample}\begin{example}}%
{ \end{example}}
%
\newenvironment{emyex}{%
\setcounter{restoretemp}{\thetheorem}
\setcounter{theorem}{\theextemp}  
\begin{example}%
}{\end{example}\setcounter{theorem}{\therestoretemp}
}



\begin{document}

\begin{frame}
\begin{example}
  This is a test example
   \end{example}

  \begin{smyex}
  Previous example.
  \end{smyex}

  \begin{example}
   Another  previous example.
  \end{example}

\end{frame}

\begin{frame}
\begin{example}
  This is a test example
   \end{example}

  \begin{emyex}
   Continued  previous example
  \end{emyex}

  \begin{example}
   Another  previous example.
  \end{example}

\end{frame}

\end{document}

enter image description here

  • This is good workaround but still not automated way. – MYaseen208 Jul 10 '13 at 16:56

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.