5

I was working on the first reply given here. However, my code contains one \section*{Intro} at the beginning, so that the bookmark numbering is incremented by one (i.e., I need that the first bookmark number is 1). How can I reduce this one!

Here's my code

\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}

Output bookmark

  • 1
    Quick fix (probably it causes other problems...): add \addtocounter{section}{-1} in the preamble. – karlkoeller Nov 21 '13 at 20:24
  • @karlkoeller Yeah, it causes serious problems. When you click on those bookmarks, you are directed to the previous section. – pushpen.paul Nov 21 '13 at 20:31
  • It was just a thought... I was sure that it might cause problems... – karlkoeller Nov 21 '13 at 20:33
4

Unfortunately, beamer doesn't really support numbered/unnumbered sections. It can however be patched to provide some attempt at this functionality.

Here, I create a new counter called realsection that only gets incremented on non-starred sections, not for starred sections (as you have noticed, section gets incremented for both in beamer). Using a new counter should be more robust than trying to tweak the existing one. This solution also has the advantage of not having to remember to manually mess around with adding minus one etc to counters.

\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

Based on the comment of @karlkoeller, I was wondering if the following placement of \addtocounter{section}{-1} might give the desired results

\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.