
以下投影機代碼
\documentclass{beamer}
\setbeamertemplate{section in toc}[sections numbered]
\begin{document}
\frame{\tableofcontents}
\section{section one}
\frame{\insertsectionnumber\quad\insertsection}
\section*{section two}
\frame{\insertsectionnumber\quad\insertsection}
\section{section three}
\frame{\insertsectionnumber\quad\insertsection}
\end{document}
給出以下結果:
我知道這\tableofcontents
會呼叫\inserttocsectionnumber
命令。當有一些\section*
命令,\inserttocsectionnumber
並\insertsectionnumber
給出不同的結果:2 第三節和3 第三節。為什麼?
答案1
這是來自 的一些程式碼beamerbasesection.sty
,帶有一些註釋
與諸如 之類的標準類相反,計數器的步進\section
之間沒有區別。因此,即使透過命令,計數器也會增加。\section*
section
article
section
\section*
這是一個錯誤嗎?不,我認為,這樣做更容易記帳所有各種複雜的功能beamer
\newcommand<>{\section}{\alt#1{\@ifnextchar[\beamer@section\beamer@@section}{\beamer@secgobble}}
\def\beamer@@section{\@ifnextchar*\beamer@@ssection\beamer@@@section}
\long\def\beamer@@ssection*#1{\beamer@section[{#1}]{}} %% starred section
\long\def\beamer@@@section#1{\beamer@section[{#1}]{#1}}
\long\def\beamer@section[#1]#2{%
\beamer@savemode%
\mode<all>%
\ifbeamer@inlecture
\refstepcounter{section}% used in any case of \section or \section*
\beamer@ifempty{#2}%
{\long\def\secname{#1}\long\def\lastsection{#1}}%
{\global\advance\beamer@tocsectionnumber by 1\relax%
\long\def\secname{#2}%
\long\def\lastsection{#1}%
\addtocontents{toc}{\protect\beamer@sectionintoc{\the\c@section}{#2}{\the\c@page}{\the\c@part}%
{\the\beamer@tocsectionnumber}}}%
{\let\\=\relax\xdef\sectionlink{{Navigation\the\c@page}{\noexpand\secname}}}%
\beamer@tempcount=\c@page\advance\beamer@tempcount by -1%
\beamer@ifempty{#1}{}{%
\addtocontents{nav}{\protect\headcommand{\protect\sectionentry{\the\c@section}{#1}{\the\c@page}{\secname}{\the\c@part}}}%
\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@sectionstartpage=\c@page%
\beamer@subsectionstartpage=\c@page%
\def\insertsection{\expandafter\hyperlink\sectionlink}%
\def\insertsubsection{}%
\def\insertsubsubsection{}%
\def\insertsectionhead{\hyperlink{Navigation\the\c@page}{#1}}%
\def\insertsubsectionhead{}%
\def\insertsubsubsectionhead{}%
\def\lastsubsection{}%
\Hy@writebookmark{\the\c@section}{\secname}{Outline\the\c@part.\the\c@section}{2}{toc}%
\hyper@anchorstart{Outline\the\c@part.\the\c@section}\hyper@anchorend%
\beamer@ifempty{#2}{\beamer@atbeginsections}{\beamer@atbeginsection}%
\fi%
\beamer@resumemode}%
編輯:
如果使用一些修補程式以防止\refstepcounter
運行\section*
\documentclass{beamer}
\usepackage{xpatch}
\makeatletter
\newif\ifisstarred% new if command
\isstarredfalse% % No starred section by default
\xpretocmd{\beamer@@ssection}{\isstarredtrue}{}{} % enable `*` mode
\xpatchcmd{\beamer@@ssection}{\beamer@section[{#1}]{}}{\beamer@section[{#1}]{}\isstarredfalse}{\typeout{Patch success beamer@@ssection}}{\typeout{Patch failure}}
\xpatchcmd{\beamer@section}{%
\refstepcounter{section}%
}{%
\ifisstarred%
% Do nothing in here
\else
\refstepcounter{section}%
\fi
}{\typeout{Patch success beamer@section}}{}
\makeatother
\setbeamertemplate{section in toc}[sections numbered]
\begin{document}
\frame{\tableofcontents}
\section{section one}
\frame{\insertsectionnumber\quad\insertsection}
%\inserttocsectionnumber
\section*{section two}
\typeout{Starred section}
\frame{\insertsectionnumber\quad\insertsection}
\section{section three}
\frame{\insertsectionnumber\quad\insertsection}
\end{document}