47

The document I'm writing using report class has 2 unnumbered chapters. The sections of the 2nd chapter are numbered following the numbering of the sections of the 1st chapter, like this:

MY FIRST UNNUMBERED CHAPTER
1 First Section
2 Second Section
3 Third Section

MY SECOND UNNUMBERED CHAPTER
4 First Section
5 Second Section

I want it to reset the section numbering every time a new unnumbered chapter is created:

MY FIRST UNNUMBERED CHAPTER
1 First Section
2 Second Section
3 Third Section

MY SECOND UNNUMBERED CHAPTER
1 First Section
2 Second Section

For this, I tried:

  • \@addtoreset{section}{chapter*}, it compiled, but sections were not correctly numbered and PDF bookmarks went crazy.
  • \setcounter{section}{0}, it correctly numbered the sections, but the PDF bookmarks of the sections of the 2nd chapter points to the first chapter.

So, how to reset the section numbers between unnumbered chapters without breaking the PDF bookmarks?

0

1 Answer 1

49

Package hyperref needs the counter values to generate unique anchor names. But there are counter values that are not unique. For example, you have several sections with number 1.

Because of this, hyperref has introduced \theH<counter> and prefers it over \the<counter> for use in anchor names. \the<counter> might contain weird or duplicate values. As long as \theH<counter> expands to a simple unique string, hyperref is happy.

The following example provides unique definitions for \theHsection:

\documentclass{report}
\usepackage{hyperref}
\usepackage{bookmark}
\bookmarksetup{
  numbered,
  open
}
\renewcommand*{\thesection}{\arabic{section}}

\begin{document}
\tableofcontents

\chapter{First numbered chapter}
\section{AB}
\section{BC}
\section{DE}

\chapter*{First unnumbered chapter}
\addcontentsline{toc}{chapter}{First unnumbered chapter}
\setcounter{section}{0}
\renewcommand*{\theHsection}{chX.\the\value{section}}
\section{FG}
\section{HI}
\section{IJ}

\chapter*{Second unnumbered chapter}
\addcontentsline{toc}{chapter}{Second unnumbered chapter}
\setcounter{section}{0}
\renewcommand*{\theHsection}{chY.\the\value{section}}
\section{KL}
\section{MN}
\section{NO}

\renewcommand*{\theHsection}{\theHchapter.\the\value{section}}

\chapter{Last numbered chapter}
\section{PQ}
\section{RS}
\section{TU}
\end{document}

Bookmarks

2
  • 1
    Just perfect! Thanks a lot for the solution and the explanation!!! Sep 13, 2012 at 9:39
  • 2
    For completeness' sake (and since Google brought me here), I would belatedly like to add that this solution also works for resetting chapters in parts in the scrbook class: \addcontentsline{toc}{part}{Moses parts the red chapter} \setcounter{chapter}{0} \renewcommand*{\theHchapter}{chX.\the\value{chapter}}
    – Paul Burgh
    Mar 27, 2018 at 15:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .