How to Reset Chapter and Section Counter with \part in LaTeX

countersnumberingsectioning

To get the output Toc or pdf bookmark below:


Part I
    Chapter I
    Chapter II
Part II
    Chapter I
    Chapter II

I need to reset the chapter counter. I google and get one method.


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

Yes, It can output like this. But hyperref package can not link to right target for chapters after chapter I. That is said page ref link broken.

I like to define all style in style file. the mini-document:


\documentclass[]{book}
\usepackage[]{hyperref}
\usepackage{mini} % my own style file

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

and the mini style file:


\renewcommand\part{%
  \if@openright
    \cleardoublepage
  \else
    \clearpage
  \fi
\setcounter{chapter}{0}} % I reset manually here.  

Best Answer

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.