我正在处理第一个回复这里。但是,我的代码\section*{Intro}
在开头包含一个,因此书签编号会加一(即,我需要第一个书签编号为 1)。我该如何减少这个!
这是我的代码
\documentclass{beamer}
\hypersetup{
bookmarksnumbered=true
}
\setcounter{tocdepth}{4}
% get numbering in section bookmarks
\usepackage{etoolbox}
\usepackage{bookmark}
\makeatletter
\patchcmd{\beamer@section}%
{\Hy@writebookmark{\the\c@section}{\secname}}%
{\Hy@writebookmark{\the\c@section}{\numberline{\thesection}\secname}}%
{}{\errmessage{failed to patch}}
\patchcmd{\beamer@subsection}%
{\Hy@writebookmark{\the\c@subsection}{#2}}%
{\Hy@writebookmark{\the\c@subsection}{\numberline{\thesection.\thesubsection}#2}}%
{}{\errmessage{failed to patch}}
\patchcmd{\beamer@subsubsection}%
{\Hy@writebookmark{\the\c@subsubsection}{#2}}%
{\Hy@writebookmark{\the\c@subsubsection}{\numberline{\thesection.\thesubsection.\thesubsubsection}#2}}%
{}{\errmessage{failed to patch}}
\makeatother
\begin{document}
\section*{Intro}
\section{section}
\begin{frame}
\end{frame}
\subsection{subsection}
\begin{frame}
\end{frame}
\subsubsection{subsubsection}
\begin{frame}
\end{frame}
\section{section}
\begin{frame}
\end{frame}
\subsection{subsection}
\begin{frame}
\end{frame}
\subsubsection{subsubsection}
\begin{frame}
\end{frame}
\subsubsection{subsubsection}
\begin{frame}
\end{frame}
\end{document}
输出
答案1
不幸的是,beamer
它并不真正支持编号/未编号部分。不过可以对其进行修补以提供此功能的一些尝试。
在这里,我创建了一个名为 的新计数器realsection
,它只会在非星号部分增加,而不会在星号部分增加(正如您所注意到的,section
在 中两者都增加beamer
)。使用新计数器应该比尝试调整现有计数器更可靠。此解决方案还具有不必记住手动在计数器上加一等优点。
\documentclass{beamer}
\hypersetup{
bookmarksnumbered=true
}
\setcounter{tocdepth}{4}
% get numbering in section bookmarks
\usepackage{etoolbox}
\usepackage{bookmark}
\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}{\numberline{\therealsection}\secname}}%
{}{\errmessage{failed to patch}}
\patchcmd{\beamer@subsection}%
{\Hy@writebookmark{\the\c@subsection}{#2}}%
{\Hy@writebookmark{\the\c@subsection}{\numberline{\therealsection.\thesubsection}#2}}%
{}{\errmessage{failed to patch}}
\patchcmd{\beamer@subsubsection}%
{\Hy@writebookmark{\the\c@subsubsection}{#2}}%
{\Hy@writebookmark{\the\c@subsubsection}{\numberline{\therealsection.\thesubsection.\thesubsubsection}#2}}%
{}{\errmessage{failed to patch}}
\makeatother
\begin{document}
\section*{Intro}
\section{section}
\begin{frame}
\end{frame}
\subsection{subsection}
\begin{frame}
\end{frame}
\subsubsection{subsubsection}
\begin{frame}
\end{frame}
\section{section}
\begin{frame}
\end{frame}
\subsection{subsection}
\begin{frame}
\end{frame}
\subsubsection{subsubsection}
\begin{frame}
\end{frame}
\subsubsection{subsubsection}
\begin{frame}
\end{frame}
\end{document}
答案2
根据评论@karlkoeller,我想知道以下放置是否\addtocounter{section}{-1}
会产生预期的结果
\documentclass{beamer}
\hypersetup{
bookmarksnumbered=true
}
\setcounter{tocdepth}{4}
% get numbering in section bookmarks
\usepackage{etoolbox}
\usepackage{bookmark}
\makeatletter
\patchcmd{\beamer@section}%
{\Hy@writebookmark{\the\c@section}{\secname}}%
{\Hy@writebookmark{\the\c@section}{\numberline{\thesection}\secname}}%
{}{\errmessage{failed to patch}}
\patchcmd{\beamer@subsection}%
{\Hy@writebookmark{\the\c@subsection}{#2}}%
{\Hy@writebookmark{\the\c@subsection}{\numberline{\thesection.\thesubsection}#2}}%
{}{\errmessage{failed to patch}}
\patchcmd{\beamer@subsubsection}%
{\Hy@writebookmark{\the\c@subsubsection}{#2}}%
{\Hy@writebookmark{\the\c@subsubsection}{\numberline{\thesection.\thesubsection.\thesubsubsection}#2}}%
{}{\errmessage{failed to patch}}
\makeatother
\begin{document}
\addtocounter{section}{-2}
\section*{Intro}
\begin{frame}
intro
\end{frame}
\addtocounter{section}{+1}
\section{section}
\begin{frame}
section1
\end{frame}
\subsection{subsection}
\begin{frame}
section1.1
\end{frame}
\subsubsection{subsubsection}
\begin{frame}
section1.1.1
\end{frame}
\section{section}
\begin{frame}
section2
\end{frame}
\subsection{subsection}
\begin{frame}
section2.1
\end{frame}
\subsubsection{subsubsection}
\begin{frame}
section2.1.1
\end{frame}
\subsubsection{subsubsection}
\begin{frame}
section2.1.2
\end{frame}
\end{document}