Beamer - 自定义 PDF 书签

Beamer - 自定义 PDF 书签

我正在用 Beamer 准备一个演示文稿,其中包括一些章节和小节。但是,我希望章节编号和小节编号出现在 PDF 书签中。我使用了以下代码,但在目录中,章节编号出现了两次。

\section[First Section]{\S~{\protect\ref{s1}} First Section}\label{s1}

如何才能获得 PDF 书签和目录的以下输出? 期望

答案1

好吧,我在这里找到了答案在 Beamer 中调整书签编号, 谢谢网络奇点。我也给出了代码。

\documentclass{beamer}

\usepackage{etoolbox}
\usepackage{bookmark}

\hypersetup{bookmarksdepth=4,bookmarksnumbered=true,bookmarksopen=true}

\usetheme{Warsaw}
\usecolortheme{seahorse}

\makeatletter
\newcounter{realsection}
\newif\ifrealsection
\long\def\beamer@@ssection*#1{\realsectionfalse\beamer@section[{#1}]{}}
\long\def\beamer@@@section#1{\realsectiontrue\beamer@section[{#1}]{#1}}

\patchcmd{\beamer@section}%
    {\refstepcounter{section}}%
    {\ifrealsection\refstepcounter{realsection}\fi\refstepcounter{section}}%
    {}{\errmessage{failed to patch}}
\patchcmd{\beamer@section}%
    {\Hy@writebookmark{\the\c@section}{\secname}}%
    {\Hy@writebookmark{\the\c@section}{\S~\numberline{\therealsection}\secname}}%
    {}{\errmessage{failed to patch}}
\patchcmd{\beamer@subsection}%
   {\Hy@writebookmark{\the\c@subsection}{#2}}%
    {\Hy@writebookmark{\the\c@subsection}{\S~\numberline{\therealsection.\thesubsection}#2}}%
    {}{\errmessage{failed to patch}}
\patchcmd{\beamer@subsubsection}%
    {\Hy@writebookmark{\the\c@subsubsection}{#2}}%
    {\Hy@writebookmark{\the\c@subsubsection}{\S~\numberline{\therealsection.\thesubsection.\thesubsubsection}#2}}%
    {}{\errmessage{failed to patch}}
\makeatother

\begin{document}

\begin{frame}{}
\tableofcontents
\end{frame}

\section*{Cover}
\pdfbookmark[2]{Cover}{Cover}

\section*{Table of Contents}
\pdfbookmark[2]{Table of Contents}{ToC}

\section{First Section}
\begin{frame}{}
\end{frame}

\end{document} 

相关内容