Beamer Metropolis 进度条:使用页码代替帧号

Beamer Metropolis 进度条:使用页码代替帧号

在 Beamer 的metropolis主题中,是否可以设置进度条,以便使用页码而不是帧号来跟踪进度?在下面的示例中,进度条不会改变,因为只有一个帧。但是,我希望进度条随着页面的每次覆盖更新而更新:

\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}

我发现metropolis文档控制进度条设置的代码片段:

\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}
}

\insertframenumber\insertpagenumber\inserttotalframenumber代替似乎很自然\inserttotalpagenumber。但是,我在Beamer 文档任何记录总页数的宏。我在尝试使用\pageref{LastPage}lastpage包时也遇到了错误。

答案1

事实证明,来自的数字\pageref{}不能用于计算。必须使用\getpagerefnumber{}。我还包含一个条件,以在标签最初未定义! Arithmetic overflow时捕获错误。LastPage

完整工作代码:

\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}

相关内容