本部分总页数

本部分总页数

对于我的文档 (beamer 演示文稿) 中的所有部分 (甚至子部分),我只想显示相对于 (子) 部分的页码,以及每个 (子) 部分的总页数。所以最后,在我的页脚中,我可以显示如下内容:

“第 1.2 节 第 3 页 / 共 10 页”

我发现重置每个部分的页码。不过,这对 Beamer 不起作用。但我认为重置页码并不难修复。我想我可以用\AtBeginSubsection某种方式来修复。

不过,我真的不知道如何计算每个(子)部分的页数。是否可以为每个(子)部分创建一个单独的计数器?怎么做?然后我需要收集所有这些计数器,并将它们的最后一个值存储到一个文件中,然后导入该文件。听起来相当简单,但我的 Latex 知识太缺乏了。

会手动为两个部分执行此操作。但我需要自动为任意数量的(子)部分执行此操作。(或者我可能误解了答案?)

这里有很多关于如何计算页码的参考资料,并且链接了 CTAN 上的许多包,例如 totcount、pageslts、totpages、lastpage 等,但从浏览它们来看,它们似乎对我没有帮助(或者至少我不知道如何帮助)。

答案1

思路如下:在每个小节末尾添加一个标签,然后使用 获取最后一个页码\pageref{}。下面的代码subsection:<number>在每一帧都添加一个标签,因此会产生许多关于重复标签的警告,但似乎有效。此外,它需要额外的调整(例如从标题页中删除页码)。

\documentclass[12pt]{beamer}

\counterwithin{subsection}{section}

\usepackage{etoolbox}

\makeatletter
\pretocmd{\frame}{\label{subsection:\thesubsection}}{}{}
\apptocmd{\beamer@section}{\setcounter{page}{1}}{}{}
\apptocmd{\beamer@subsection}{\setcounter{page}{1}}{}{}
\setbeamertemplate{footline}{%
  \hfill
  Section \thesubsection, page
  \thepage/\pageref{subsection:\thesubsection}%
}
\beamertemplatenavigationsymbolsempty

\makeatother

\begin{document} 

\title{Title} 
\author{Author}
\institute{Firm}
\date{Date} 

\frame{\titlepage}

\section{First section}
\subsection{First subsection}

\begin{frame}
    \frametitle{Title}
\end{frame}

\begin{frame}
    \frametitle{Title}
\end{frame}

\begin{frame}
    \frametitle{Title}
\end{frame}

\subsection{Second subsection}

\begin{frame}
    \frametitle{Title}
\end{frame}

\begin{frame}
    \frametitle{Title}
\end{frame}

\end{document}

在此处输入图片描述

答案2

与此同时,经过多次尝试和错误,我想出了一个自己的解决方案。虽然可行,但有点丑陋,需要进行大量调整才能使某些边缘情况变得更好或更正确,例如,第一个(子)部分或最后一个(子)部分的表现不太正确。

主要代码/想法的灵感来自于这里,然后被采纳。

\documentclass[handout, t]{beamer}
\usefonttheme[onlymath]{serif}

\usepackage{lmodern}
%\usepackage[default]{sourcesanspro}
\usepackage[utf8]{inputenc}
% See mail / GitHub for discussion on fontenc.
\usepackage[T1]{fontenc}  % always recommended, https://tex.stackexchange.com/questions/1774
\renewcommand*\familydefault{\sfdefault}
\usepackage{amssymb}
\usepackage{pifont}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{makecell}
\usepackage{booktabs}
\usepackage{ulem}
\usepackage{lastpage}

% ...
% other imports, setup, ...
% ...

% stuff from my beamer template:

% custom header
\defbeamertemplate*{headline}{rwth}{

% distance of section from the page top
\vspace{4mm}

\hbox{%
%
  \hspace*{8mm}%
%
\begin{beamercolorbox}[wd=\framelinewidth,ht=13mm]{section in head/foot}%
\ifx\subsecname\empty%
{\usebeamerfont{section in head/foot}\insertsectionhead}\\

\hspace*{1em}\Large\usebeamerfont{subsection}{}\strut%
\else%
{\usebeamerfont{subsection}\Large\normalfont\insertsectionhead%
\usebeamerfont{section in head/foot}}\\

% note: by intention, use section font (larger, bold) for subsection title
\hspace*{1em}\usebeamerfont{section}\insertsubsectionhead\strut%
\ifnum\value{subsubsection}=0%
\else%
: \insertsubsubsectionhead\strut%
\fi%
\vspace{-2pt}
\fi%
\end{beamercolorbox}%
%
  \hspace*{8mm}%
%
}%

\defbeamertemplate*{footline}{rwth}{
% ...
\insertframenumbering
% ...
}

% end of beamer template stuff

% now the page number stuff

\AtBeginSection[]{%
\let\subsecname\empty%
\let\subsubsecname\empty%
\setcounter{subsection}{0}%
\setcounter{subsubsection}{0}%
\deffirstlastpagecounters{}%
}

\AtBeginSubsection[]{
\deffirstlastpagecounters{}%
\setcounter{subsubsection}{-1}%
\subsubsection*{Outline}
\begin{frame}
\tableofcontents[sectionstyle=show/hide,subsectionstyle=show/shaded/hide,subsubsectionstyle=show/show/hide]
\end{frame}
\setcounter{subsubsection}{-1}%
\clearpage
\subsubsection*{}
\let\subsubsecname\empty%
}


% Counter calculation not needed anymore with page numbers per subsection.
% https://tex.stackexchange.com/questions/2541/beamer-frame-numbering-in-appendix
\newcommand{\backupbegin}{
% Use it one last time.
\deffirstlastpagecounters{}
% Ref to one after last page.
\setcounterpageref{seclastpage}{LastPage}
\addtocounter{seclastpage}{1}
% Now disable it.
\let\deffirstlastpagecounters\empty%
   %\newcounter{framenumberappendix}
   %\setcounter{framenumberappendix}{\value{framenumber}}
}
\newcommand{\backupend}{
   %\addtocounter{framenumberappendix}{-\value{framenumber}}
   %\addtocounter{framenumber}{\value{framenumberappendix}}
}

% Inspired via https://tex.stackexchange.com/questions/232785/numbers-for-first-and-last-page-of-chapters
\newcounter{subsecabs}  % absolute sub section
\newcounter{secfirstpage}
\newcounter{seclastpage}
\def\deffirstlastpagecounters{%
  \ifnum\value{subsecabs}=0\else% If _not_ the first chapter
    \label{sec\thesubsecabs:lastpage}% Insert an end-of-chapter \label
  \fi%
  %\clearpage
  \addtocounter{subsecabs}{1}%
  \label{sec\thesubsecabs:firstpage}% Insert a start-of-chapter \label
  \setcounterpageref{secfirstpage}{sec\thesubsecabs:firstpage}%
  \setcounterpageref{seclastpage}{sec\thesubsecabs:lastpage}%
}
%\AtBeginSection[]{\deffirstlastpagecounters{}}
%\AtBeginSubsection[]{\deffirstlastpagecounters{}}
\AtBeginDocument{\deffirstlastpagecounters{}}
%\AtEndDocument{\label{sec\number\value{subsecabs}:lastpage}}

%\newcommand{\insertframenumbering}{\insertframenumber{} of \inserttotalframenumber}
% counters: \thepage -- \theframenumber -- \thesecfirstpage -- \theseclastpage
\newcommand{\insertframenumbering}{%
\ifnum\value{section}=1%
    Introduction%
\else
    \ifnum\value{subsection}=0%
    Section \number\numexpr\thesection-1%
    \else
    Section \number\numexpr\thesection-1.\thesubsection%
    \fi%
\fi,\\
page \number\numexpr\thepage-\thesecfirstpage+1{} of \number\numexpr\theseclastpage-\thesecfirstpage}

% ...
% other stuff
% ...

\begin{document}

\section*{Introduction}

\input{section_introduction}


\section{Part 1: ...}
\begin{frame}
\vfill
\begin{center}
 \secname
 % Or sth more custom?
 % Or just outline again?
\end{center}
\vfill
\end{frame}


\subsection{Sub 1 ...}
\input{section_part1_sub1}



\subsection{Conclusion}
\input{section_part1_conclusion}


\section{Part 2: ...}
\begin{frame}
\vfill
\begin{center}
 \secname
\end{center}
\vfill
\end{frame}


\subsection{Introduction}

% ...

\section{Conclusion}
\input{section_conclusion}


\setbeamertemplate{final page}[rwth][Any questions?]{Thank you for your attention}
\begin{frame}[plain]
\usebeamertemplate{final page}
\end{frame}


\appendix
\backupbegin

%\section{Appendix}
% ... (in case we need any appendix)

\section{References}

\begin{frame}[allowframebreaks]
    \centerline{Reference}
    %\bibliographystyle{ieeetr}
    \bibliographystyle{i6bibstyle}
    \bibliography{references}
\end{frame}

\backupend

\end{document}

相关内容