在 Beamer 中使用 \part 时如何保留子部分计数器?

在 Beamer 中使用 \part 时如何保留子部分计数器?

我使用 Beamer 创建我的讲义。我用它\part{}来区分各个讲座。但是,我发现如果某个部分以小节开头,那么小节计数器会自动重置。我该如何避免这种情况?

这是一个最小的运行示例。第二部分中的子节计数器被重置为 1,该计数器应该是 3。


\documentclass{beamer}
\useoutertheme[width = 1.5cm, height = 1cm]{sidebar}
\begin{document}


%=================== Lecture 1 ======================
\part{}
\section{section 1}
\subsection{subsection 1.1}
\subsection{subsection 1.2}
\section{section 2}
\subsection{subsection 2.1}
\subsection{subsection 2.2}
\begin{frame}{Page 1}
     The section counter in Part \thepart is \thesection.\\
     The subsection counter in Part \thepart is \thesubsection.
\end{frame}


\part{}
\subsection{subsection 2.3}
\begin{frame}{Page 2}
    The section counter in Part \thepart is \thesection.\\
     The subsection counter in Part \thepart is \thesubsection.
\end{frame}
\end{document}

在此处输入图片描述

答案1

从重复的问题中复制而来https://github.com/josephwright/beamer/issues/611

\documentclass{beamer}

\useoutertheme[width = 1.5cm, height = 1cm]{sidebar}

\makeatletter
\renewcommand<>{\part}{\alt#1{\@dblarg\beamer@part}{\beamer@gobbleoptional}}
\long\def\beamer@part[#1]#2{%
  \beamer@savemode
  \mode<all>%
  \ifbeamer@inlecture
    \refstepcounter{part}%
    \def\beamer@partname{#2}%
    \def\beamer@partnameshort{#1}%
    \addtocontents{nav}{\protect\headcommand{\protect\partentry{#2}{\the\c@part}}}%
    \xdef\partlink{{Navigation\the\c@page}{\noexpand\beamer@partname}}%
    \xdef\partlinkshort{{Navigation\the\c@page}{\noexpand\beamer@partnameshort}}%
    \beamer@tempcount=\c@page\advance\beamer@tempcount by -1%
    \addtocontents{nav}{\protect\headcommand{%
        \protect\beamer@partpages{\the\beamer@partstartpage}{\the\beamer@tempcount}}}%
    \addtocontents{nav}{\protect\headcommand{%
        \protect\beamer@sectionpages{\the\beamer@sectionstartpage}{\the\beamer@tempcount}}}%
    \addtocontents{nav}{\protect\headcommand{%
        \protect\beamer@subsectionpages{\the\beamer@subsectionstartpage}{\the\beamer@tempcount}}}%
    \beamer@partstartpage=\c@page
    \beamer@sectionstartpage=\c@page
    \beamer@subsectionstartpage=\c@page
%    \setcounter{subsection}{0}%
    \protected\def\insertsection{}%
    \protected\def\insertsubsection{}%
    \protected\def\insertsubsubsection{}%
    \protected\def\insertsectionhead{}%
    \protected\def\insertsubsectionhead{}%
    \protected\def\insertsubsubsectionhead{}%
    \def\lastsubsection{}%
    \protected\def\insertpart{\expandafter\hyperlink\partlink}%
    \Hy@writebookmark{\the\c@part}{#1}{Outline\the\c@part}{1}{toc}%
    \hyper@anchorstart{Outline\the\c@part}\hyper@anchorend
    \beamer@atbeginpart
  \fi%
  \beamer@resumemode}%
\makeatother

\begin{document}


%=================== Lecture 1 ======================
\part{}
\section{section 1}
\subsection{subsection 1.1}
\subsection{subsection 1.2}
\section{section 2}
\subsection{subsection 2.1}
\subsection{subsection 2.2}
\begin{frame}{Page 1}
     The section counter in Part \thepart is \thesection.\\
     The subsection counter in Part \thepart is \thesubsection.
\end{frame}


\part{}
\subsection{subsection 2.3}
\begin{frame}{Page 2}
    The section counter in Part \thepart is \thesection.\\
     The subsection counter in Part \thepart is \thesubsection.
\end{frame}
\end{document}

答案2

你可以尝试一下这个!

\documentclass{beamer}
\usetheme{Hannover}
\setbeamertemplate{section in toc}[sections numbered]
\setbeamertemplate{subsection in toc}[subsections numbered]
\setbeamertemplate{subsubsection in toc}[subsubsections numbered]
\setcounter{secnumdepth}{3}

\begin{document}
\begin{frame}{Titre}
\tableofcontents
\end{frame}
\section{Rappels}
\subsection{Fondements}
\begin{frame}{Titre}
Bla bla.
\end{frame}

\begin{frame}{Titre}
Bla bla.
\end{frame}

\begin{frame}{Titre}
Bla bla.
\end{frame}
\subsection{Implications}
\begin{frame}{Titre}
Bla bla.
\end{frame}
\subsection{Critiques}
\begin{frame}{Titre}
Bla bla.
\end{frame}
\section{Th\'eorie}
\subsection{Plan}
\begin{frame}{Titre}
Bla bla.
\end{frame}
\subsection{\'Equilibre}
\begin{frame}{Titre}
Bla bla.
\end{frame}
\end{document}
Haut

相关内容