Beamer:包含页码的目录,直至子章节

Beamer:包含页码的目录,直至子章节

感谢 Gonzalo Medina 的精彩代码(带页码的目录),可以显示目录中各节和子节的帧编号。如果我的目录有子子节。这些子子节在目录中没有帧编号。我想可以修改上述代码。但是,我只是一个 beamer 初学者。所以任何帮助我都非常感谢。

在此处输入图片描述

以下是代码:

\documentclass{beamer}
\usetheme{CambridgeUS}

\newcounter{sectionpage}

\makeatletter
\long\def\beamer@section[#1]#2{%
    \beamer@savemode%
    \mode<all>%
    \ifbeamer@inlecture
    \refstepcounter{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}%
        \setcounter{sectionpage}{\insertframenumber}\stepcounter{sectionpage}%
        \addtocontents{toc}{\protect\beamer@sectionintoc{\the\c@section}{#2\dotfill\thesectionpage}{\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}%

\def\beamer@subsection[#1]#2{%
    \beamer@savemode%
    \mode<all>%
    \ifbeamer@inlecture%
    \refstepcounter{subsection}%
    \beamer@ifempty{#2}{\long\def\subsecname{#1}\long\def\lastsubsection{#1}}
    {%
        \long\def\subsecname{#2}%
        \long\def\lastsubsection{#1}%
        \setcounter{sectionpage}{\insertframenumber}\stepcounter{sectionpage}%
        \addtocontents{toc}{\protect\beamer@subsectionintoc{\the\c@section}{\the\c@subsection}{#2\dotfill\thesectionpage}{\the\c@page}{\the\c@part}{\the\beamer@tocsectionnumber}}%
    }%
    \beamer@tempcount=\c@page\advance\beamer@tempcount by -1%
    \addtocontents{nav}{%
        \protect\headcommand{\protect\beamer@subsectionentry{\the\c@part}{\the\c@section}{\the\c@subsection}{\the\c@page}{\lastsubsection}}%
        \protect\headcommand{\protect\beamer@subsectionpages{\the\beamer@subsectionstartpage}{\the\beamer@tempcount}}%
    }%
    \beamer@subsectionstartpage=\c@page%
    \edef\subsectionlink{{Navigation\the\c@page}{\noexpand\subsecname}}%
    \def\insertsubsection{\expandafter\hyperlink\subsectionlink}%
    \def\insertsubsubsection{}%
    \def\insertsubsectionhead{\hyperlink{Navigation\the\c@page}{#1}}%
    \def\insertsubsubsectionhead{}%
    \Hy@writebookmark{\the\c@subsection}{#2}{Outline\the\c@part.\the\c@section.\the\c@subsection.\the\c@page}{3}{toc}%
    \hyper@anchorstart{Outline\the\c@part.\the\c@section.\the\c@subsection.\the\c@page}\hyper@anchorend%
    \beamer@ifempty{#2}{\beamer@atbeginsubsections}{\beamer@atbeginsubsection}%
    \fi%
    \beamer@resumemode}

\makeatother

\AtBeginSection[] % Do nothing for \section*
{
    \begin{frame}<beamer>
        \frametitle{Outline}
        \tableofcontents[currentsection]
    \end{frame}
}


\begin{document}
    
    \begin{frame}
        \frametitle{Outline}
        \tableofcontents
    \end{frame}
    
    \section{Test Section One}
    \begin{frame}test1\pause test11\end{frame}
    \subsection{Test Subsection One One}
    \begin{frame}test2\end{frame}
    \begin{frame}test3\end{frame}
    \subsubsection{Test Subsubsection One One One}
    \begin{frame}test2\end{frame}
    \begin{frame}test3\end{frame}
    \subsubsection{Test Subsubsection One One Two}
    \begin{frame}test2\end{frame}
    \begin{frame}test3\end{frame}
    \subsection{Test Subsection One Two}
    \begin{frame}test4\end{frame}
    \begin{frame}test5\end{frame}
    
    \section{Test Section Two}
    \begin{frame}test6\end{frame}
    \subsection{Test Subsection Two One}
    \begin{frame}test7\end{frame}
    \begin{frame}test8\end{frame}
    \begin{frame}test9\end{frame}
    \subsection{Test Subsection Two Two}
    \begin{frame}test10\end{frame}
    
\end{document}

答案1

欢迎来到 TeX.SX!您提供的代码本质上只是复制了默认命令并添加了页码。因此,您只需对 执行相同操作即可\beamer@subsubsection

不过,我建议您修补底层命令而不是复制整个定义,以减少序言中的代码量。

\documentclass{beamer}
\usetheme{CambridgeUS}
    
\newcounter{sectionpage}
\makeatletter

\patchcmd{\beamer@section}
    {\addtocontents{toc}{\protect\beamer@sectionintoc{\the\c@section}{#2}{\the\c@page}{\the\c@part}{\the\beamer@tocsectionnumber}}}
    {\setcounter{sectionpage}{\insertframenumber}\stepcounter{sectionpage}%
     \addtocontents{toc}{\protect\beamer@sectionintoc{\the\c@section}{#2\dotfill\thesectionpage}{\the\c@page}{\the\c@part}{\the\beamer@tocsectionnumber}}}
    {}{}
    
\patchcmd{\beamer@subsection}
    {\addtocontents{toc}{\protect\beamer@subsectionintoc{\the\c@section}{\the\c@subsection}{#2}{\the\c@page}{\the\c@part}{\the\beamer@tocsectionnumber}}}
    {\setcounter{sectionpage}{\insertframenumber}\stepcounter{sectionpage}%
     \addtocontents{toc}{\protect\beamer@subsectionintoc{\the\c@section}{\the\c@subsection}{#2\dotfill\thesectionpage}{\the\c@page}{\the\c@part}{\the\beamer@tocsectionnumber}}}
    {}{}
    
\patchcmd{\beamer@subsubsection}
    {\addtocontents{toc}{\protect\beamer@subsubsectionintoc{\the\c@section}{\the\c@subsection}{\the\c@subsubsection}{#2}{\the\c@page}{\the\c@part}{\the\beamer@tocsectionnumber}}}
    {\setcounter{sectionpage}{\insertframenumber}\stepcounter{sectionpage}%
     \addtocontents{toc}{\protect\beamer@subsubsectionintoc{\the\c@section}{\the\c@subsection}{\the\c@subsubsection}{#2\dotfill\thesectionpage}{\the\c@page}{\the\c@part}{\the\beamer@tocsectionnumber}}}
    {}{}

\makeatother

\AtBeginSection[] % Do nothing for \section*
{
    \begin{frame}<beamer>
        \frametitle{Outline}
        \tableofcontents[currentsection]
    \end{frame}
}

\begin{document}
    
    \begin{frame}
        \frametitle{Outline}
        \tableofcontents
    \end{frame}
    
    \section{Test Section One}
    \begin{frame}test1\pause test11\end{frame}
    \subsection{Test Subsection One One}
    \begin{frame}test2\end{frame}
    \begin{frame}test3\end{frame}
    \subsubsection{Test Subsubsection One One One}
    \begin{frame}test2\end{frame}
    \begin{frame}test3\end{frame}
    \subsubsection{Test Subsubsection One One Two}
    \begin{frame}test2\end{frame}
    \begin{frame}test3\end{frame}
    \subsection{Test Subsection One Two}
    \begin{frame}test4\end{frame}
    \begin{frame}test5\end{frame}
    
    \section{Test Section Two}
    \begin{frame}test6\end{frame}
    \subsection{Test Subsection Two One}
    \begin{frame}test7\end{frame}
    \begin{frame}test8\end{frame}
    \begin{frame}test9\end{frame}
    \subsection{Test Subsection Two Two}
    \begin{frame}test10\end{frame}
    
\end{document}

在此处输入图片描述

相关内容