Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 13 down vote accepted

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

share|improve this answer
    
Just perfect! Thanks a lot for the solution and the explanation!!! –  Fernando Lemos Sep 13 '12 at 9:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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