2

In beamer, when \onlys used, how can I make the page numbers reflect them?

For example,

\documentclass{beamer}

\usetheme[sectionpage=none,progressbar=frametitle]{metropolis}

\begin{document}
\begin{frame}
  \only<1>{
    Slide 1--1
  }
  \only<2>{
    Slide 1--2
  }
\end{frame}

\begin{frame}
  \only<1>{
    Slide 2--1
  }
  \only<2>{
    Slide 2--2
  }
\end{frame}
\end{document}

I would like to have page numbers to be 1--1, 1--2, 2--1, 2--2 on these 4 slides, respectively.

Another example:

\documentclass[12pt,aspectratio=169,usenames,dvipsnames]{beamer}

\usetheme[sectionpage=none,progressbar=frametitle]{metropolis}

\begin{document}
\begin{frame}
  Slide 1
\end{frame}

\begin{frame}
  \textcolor<2>{red}{\color<3,8>{blue} Hi}
\end{frame}

\begin{frame}
  Slide 3
\end{frame}
\end{document}

Slides 1 and 3 should not show the post-dash part.

4
\documentclass{beamer}

\usetheme[sectionpage=none,progressbar=frametitle]{metropolis}

\newcounter{slideinframe}

\setbeamertemplate{frame numbering}{%
    \ifnum\insertframeendpage>\insertframestartpage
        \setcounter{slideinframe}{\thepage}%
        \addtocounter{slideinframe}{-\insertframestartpage}%
        \addtocounter{slideinframe}{1}%
        \insertframenumber{} -- \theslideinframe%
      \else
        \insertframenumber{}
  \fi%
}

\begin{document}

\begin{frame}
  Slide 1
\end{frame}

\begin{frame}
  \textcolor<2>{red}{\color<3,18>{blue} Hi}
\end{frame}

\begin{frame}
  Slide 3
\end{frame}

\end{document}

With an up-to-date beamer version, the code can be simplified to:

\documentclass{beamer}

\usetheme[sectionpage=none,progressbar=frametitle]{metropolis}

\setbeamertemplate{frame numbering}{%
  \ifnum\insertframeendpage>\insertframestartpage{}
        \insertframenumber{} -- \insertoverlaynumber{}%
  \else
        \insertframenumber{}
  \fi%
}
\makeatother

\begin{document}

\begin{frame}
  Slide 1
\end{frame}

\begin{frame}
  \textcolor<2>{red}{\color<3,18>{blue} Hi}
\end{frame}

\begin{frame}
  Slide 3
\end{frame}

\end{document}
  • I've always wondered why something like this is not pre-programmed in beamer... – campa Aug 18 '17 at 10:25
  • @campa It kind of is, just not in a single counter as beamer treats new slides caused by overlays and new slides caused by things like allowframebreak separately. – user36296 Aug 18 '17 at 10:32
  • Thanks! Is it possible to have single-slide frames not having the post-dash part? – xuhdev Aug 18 '17 at 17:14
  • @xuhdev please see my updated answer – user36296 Aug 18 '17 at 17:18
  • It seems that single-slide frames after multi-slide frames are broken... – xuhdev Aug 18 '17 at 19:00

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.