How to reset chapter and section counter with \part

This small example is working fine for me:

\documentclass[]{book}
\usepackage[]{hyperref}

\makeatletter
\@addtoreset{chapter}{part}
\makeatother  

\begin{document}
\tableofcontents
\part{Test}
\chapter{One}
\chapter{Two}
\part{Test}
\chapter{Three}
\chapter{Four}
\end{document}

So please provide your minimal example showing the problem. Thank you.


The problem is not one of counters but your redefinition of part. Your command \part, just handles page opening then it zeroes the chapter. Since your counter is not a subsidiary counter of part the link for the first chapter 1 and the second chapter 1 is the same.

As a matter of fact pdfTeX issues a warning:

pdfTeX warning (ext4): destination with the same identifier (name{chapter.1}) 
has been  already used, duplicate ignored

Like web hyperlinks, you cannot have a link pointing to two different destinations.

To correct the issue you can add the chapter counter to the reset list,

   \makeatletter
   \@addtoreset{chapter}{part}
   \makeatother  

or save book.cls to mybook.cls and change the line \newcounter {chapter} to:

   \newcounter {chapter}[part]

This will work provided you have a proper definition of part (that increments a part counter). As a matter of interest your redefinition of \part does nothing really other than give you trouble. It accepts no parameters! (Have a look at book.cls for similar definitions).


You should use the chngcntr package, which in essence is equivalent to \@addtoreset{chapter}{part}. But it's cleaner to use a package isn't it ;)

Also, notice that it should be loaded after the hyperref and bookmark packages to ensure the links are correct.

\documentclass{book}

\usepackage{hyperref}
\usepackage{chngcntr}
\counterwithin{chapter}{part}

\begin{document}
\tableofcontents

\part{Test}
\chapter{One}

\part{Test2}
\chapter{Two}

\end{document}

In addition, \counterwithin will rename all chapter/section/etc. labels and prepend the part to it, e.g. section 2.2. becomes IV.2.2 or whatever. If you don't want this, use \counterwithin*.