我正在使用 LaTeX Beamer 帧计数器来显示
\insertframenumber/\inserttotalframenumber
...这意味着如果我的项目有 20 帧,幻灯片在第 16 帧,“16/20”被展示。
我的项目包含很长的部分(它们反映了书的章节),我希望每个部分的框架都有一个该部分本地的计数器。
例如,如果第 16 帧实际上在第 2 部分,而第 1 部分有 5 帧,那么它应该显示“11/15”。
也许有一个解决方案,但我对此表示怀疑,因为据我所知,\AtBeginSection
没有好的计算方法。\inserttotalframenumber
如果有帮助的话,这里是我当前设置的 MWE(帧数较少):
%%% Preamble %%%
\documentclass{beamer}
\usetheme{Antibes}
\usebeamercolor{dolphin}
% Make slide numbers appear, and they appear next to navigation
\addtobeamertemplate{navigation symbols}{}{%
\usebeamerfont{footline}%
\usebeamercolor[fg]{footline}%
\hspace{1em}%
\insertframenumber/\inserttotalframenumber
}
%%% Document %%%
\begin{document}
\section{First section}
\begin{frame}
\frametitle{First}
This frame should show ``1/2'', not ``1/5''.
\end{frame}
\begin{frame}
\frametitle{Second}
This frame should show ``2/2'', not ``2/5''.
\end{frame}
\section{Second section}
\begin{frame}
\frametitle{Third}
This frame should show ``1/3'', not ``3/5''.
\end{frame}
\begin{frame}
\frametitle{Fourth}
This frame should show ``2/3'', not ``4/5''.
\end{frame}
\begin{frame}
\frametitle{Fifth}
This frame should show ``3/3'', not ``5/5''.
\end{frame}
\end{document}
答案1
以下方法在.aux
每个\section
(包括文档末尾)处插入一个“标签”,以便捕获当前帧号。捕获的帧号(\section
由于chngcntr
) 随后插入页脚。
\documentclass{beamer}
\usetheme{Antibes}
\usebeamercolor{dolphin}
\usepackage{chngcntr}
\counterwithin{framenumber}{section}% Number frames within \section
% Make slide numbers appear, and they appear next to navigation
\addtobeamertemplate{navigation symbols}{}{%
\usebeamerfont{footline}%
\usebeamercolor[fg]{footline}%
\hspace{1em}%
\insertframenumber/\inserttotalframenumberbysection
}
\makeatletter
\let\oldsection\section
\renewcommand{\section}{% Store current \section's frame count
\immediate\write\@auxout{\global\noexpand\@namedef{s@totalsectionframes-\arabic{section}}{\arabic{framenumber}}}%
\oldsection
}
\AtEndDocument{% Store final \section's frame count
\immediate\write\@auxout{\global\noexpand\@namedef{s@totalsectionframes-\arabic{section}}{\arabic{framenumber}}}%
}
\newcommand{\inserttotalframenumberbysection}{\csname s@totalsectionframes-\arabic{section}\endcsname}%
\makeatother
\begin{document}
\section{First section}
\begin{frame}
\frametitle{First}
This frame shows ``1/2'', not ``1/5''.
\end{frame}
\begin{frame}
\frametitle{Second}
This frame shows ``2/2'', not ``2/5''.
\end{frame}
\section{Second section}
\begin{frame}
\frametitle{Third}
This frame shows ``1/3'', not ``3/5''.
\end{frame}
\begin{frame}
\frametitle{Fourth}
This frame shows ``2/3'', not ``4/5''.
\end{frame}
\begin{frame}
\frametitle{Fifth}
This frame shows ``3/3'', not ``5/5''.
\end{frame}
\end{document}