1

In Beamer's metropolis theme, is it possible to set the progress bar so that it tracks progress using page numbers instead of frame numbers? In the following example, the progress bar doesn't change because there's just one frame. However, I'd like the progress bar to update as the page updates with each overlay:

\documentclass{beamer}
\usetheme[progressbar=frametitle]{metropolis}
\begin{document}

\begin{frame}{Title}
\begin{itemize}[<+->]
  \item Some item \item Some item \item Some item \item Some item \item Some item \item Some item \item Some item 
\end{itemize}
\end{frame}

\end{document}

I found in the metropolis documentation a snippet that controls the progress bar setting:

\setbeamertemplate{progress bar in head/foot}{
  \nointerlineskip
  \setlength{\metropolis@progressinheadfoot}{%
    \paperwidth * \ratio{\insertframenumber pt}{\inserttotalframenumber pt}%
  }%
  \begin{beamercolorbox}[wd=\paperwidth]{progress bar in head/foot}
  \begin{tikzpicture}
    \fill[bg] (0,0) rectangle (\paperwidth, \metropolis@progressinheadfoot@linewidth); 
    \fill[fg] (0,0) rectangle (\metropolis@progressinheadfoot, \metropolis@progressinheadfoot@linewidth);
  \end{tikzpicture}%
  \end{beamercolorbox}
}

It would seem natural to replace \insertframenumber with \insertpagenumber and \inserttotalframenumber with \inserttotalpagenumber. However, I couldn't find in the Beamer documentation any macro that records the total page number. I also got an error when trying to use \pageref{LastPage} with the lastpage package.

1 Answer 1

1

It turns out that the number from \pageref{} cannot be used for calculations. One has to use \getpagerefnumber{}. I also include a conditional to catch the ! Arithmetic overflow error when the LastPage label is initially undefined.

Full working code:

\documentclass{beamer}
\usetheme[progressbar=frametitle]{metropolis}
\usepackage{lastpage}

\makeatletter
\newcommand\insertlastpagenum{
  \@ifundefined{r@LastPage}{1}{\getpagerefnumber{LastPage}}
}
\setbeamertemplate{progress bar in head/foot}{
  \nointerlineskip
  \setlength{\metropolis@progressinheadfoot}{%
    \paperwidth * \ratio{\insertpagenumber pt}{\insertlastpagenum pt}%
  }%
  \begin{beamercolorbox}[wd=\paperwidth]{progress bar in head/foot}
  \begin{tikzpicture}
    \fill[bg] (0,0) rectangle (\paperwidth, \metropolis@progressinheadfoot@linewidth); 
    \fill[fg] (0,0) rectangle (\metropolis@progressinheadfoot, \metropolis@progressinheadfoot@linewidth);
  \end{tikzpicture}%
  \end{beamercolorbox}
}
\makeatother

\begin{document}

\begin{frame}{Title}
\begin{itemize}[<+->]
  \item Some item \item Some item \item Some item \item Some item \item Some item \item Some item \item Some item\label<.->{pp} 
\end{itemize}
\end{frame}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .