2

Suppose I have a beamer presentation with some contiguous frames containing a "special content" that are inside a specialcontent environment. I'd like to introduce this special content with a frame that display both:

  • the numbers of "special" frames,
  • the frame (not page) number of the last "special frame,

as in the MCE below (<total number of frames> and <number of last frame of the special content>).

How could I achieve this?

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\setbeamertemplate{footline}[frame number]
\setbeamertemplate{navigation symbols}{}

\newenvironment{specialcontent}{%
  \begin{frame}
    \frametitle{Special content}
    The following special content:
    \begin{itemize}
    \item has <total number of frames> frames,
    \item ends frame \# <number of last frame of the special content>.
    \end{itemize}
  \end{frame}
}{%
}

\begin{document}
\begin{frame}
  \frametitle{Foo bar}
  Foo\pause{} bar.
\end{frame}

\begin{specialcontent}

  \begin{frame}
    \frametitle{Foo bar (special content)}
    Foo\pause{} bar.
  \end{frame}

  \begin{frame}
    \frametitle{Foo bar (special content)}
    Foo\pause{} bar.
  \end{frame}

\end{specialcontent}

\begin{frame}
  \frametitle{Foo bar}
  Foo\pause{} bar.
\end{frame}
\end{document}
2

Using the totcount package:

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\setbeamertemplate{footline}[frame number]
\setbeamertemplate{navigation symbols}{}


\usepackage{totcount}
\newcounter{endspecial}
\newcounter{startspecial}
\regtotcounter{endspecial}


\newenvironment{specialcontent}{%
  \begin{frame}
    \frametitle{Special content}
    The following special content:
    \begin{itemize}
    \setcounter{startspecial}{\totvalue{endspecial}}
    \addtocounter{startspecial}{1}
    \addtocounter{startspecial}{-\insertframenumber}
    \item has \thestartspecial  <total number of frames> frames,
    \item ends frame \total{endspecial} <number of last frame of the special content>.
    \end{itemize}
  \end{frame}
}{%
  \setcounter{endspecial}{\insertframenumber}
}

\begin{document}
\begin{frame}
  \frametitle{Foo bar}
  Foo\pause{} bar.
\end{frame}

\begin{specialcontent}

  \begin{frame}
    \frametitle{Foo bar (special content)}
    Foo\pause{} bar.
  \end{frame}

  \begin{frame}
    \frametitle{Foo bar (special content)}
    Foo\pause{} bar.
  \end{frame}

\end{specialcontent}

\begin{frame}
  \frametitle{Foo bar}
  Foo\pause{} bar.
\end{frame}
\end{document}

enter image description here

  • Thanks to your comments, I realized the package I was looking for was indeed totcount. Nicely, quickly and efficiently done, as usual :) – Denis Bitouzé Mar 27 '18 at 15:23
  • @DenisBitouzé Thanks a lot for your kind words! – user36296 Mar 27 '18 at 15:24
  • If I'm right, \addtocounter{startspecial}{1} should be removed, otherwise the numbers of special frames is 3 instead of 2. – Denis Bitouzé Mar 27 '18 at 15:40
  • @DenisBitouzé Depends if you want to count the one with \frametitle{Special content}? – user36296 Mar 27 '18 at 15:43
  • 1
    @DenisBitouzé My count goes like this: 2 frames within the environment + 1 which is created by it = 3 – user36296 Mar 27 '18 at 15:45
1

For the record, I present here a extended solution to samcarter's one which works also in the case where several occurrences of specialcontents environment are to be used (and, say, this environment is not ours but given by a third party package or class -- in my real use case, it comes from the versions package).

The tricky problem was, when defining many "total counters" on the fly, only the last one was created. Thanks to the egreg's trick, the following is working like a charm:

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{multido}
\usepackage{totcount}

\usetheme{PaloAlto}
\useoutertheme{infolines}

\setbeamertemplate{navigation symbols}{}

\newenvironment{specialcontent}{%
}{%
}

\AtBeginEnvironment{specialcontent}{%
  \stepcounter{specialcontent@cntr}%
  %
  \begingroup\edef\x{\endgroup
    \noexpand\newtotcounter{startspecial@\roman{specialcontent@cntr}}
    \noexpand\newtotcounter{endspecial@\roman{specialcontent@cntr}}%
  }\x
  %
  \begin{frame}
    \frametitle{Special content (begins)}
    %
    \setcounter{startspecial@\roman{specialcontent@cntr}}{\totvalue{endspecial@\roman{specialcontent@cntr}}}%
    \addtocounter{startspecial@\roman{specialcontent@cntr}}{-\insertframenumber}%
    %
    The following special content:
    \begin{itemize}
    \item \alert{has \total{startspecial@\roman{specialcontent@cntr}} frames},
    \item \alert{ends frame \total{endspecial@\roman{specialcontent@cntr}}}.
    \end{itemize}
  \end{frame}
}

\AtEndEnvironment{specialcontent}{%
  \setcounter{endspecial@\roman{specialcontent@cntr}}{\insertframenumber}%
}

\newcounter{specialcontent@cntr}%

\begin{document}

\multido{\i=1+1}{17}{%
  \begin{frame}
    \frametitle{Foo bar}
    Foo\pause{} bar.
  \end{frame}
  %
  \section{Special \i{}}
  %
  \begin{specialcontent}
    \multido{\I=1+1}{\i}{%
      \begin{frame}
        \frametitle{Foo bar (special content)}
        Foo\pause{} bar.
      \end{frame}
    }
  \end{specialcontent}
  %
  \begin{frame}
    \frametitle{Foo bar}
    Foo\pause{} bar.
  \end{frame}
}

\end{document}

enter image description here

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.