2

I have a document divided in parts, sections and subsections and each part starts with "section 1". I totally dislike this, but I cannot change that. So sadly, I have to cope with the arising problems: After setting back the counter, the hyperlinks in the table of contents are incorrect. Each "section 1" links to the first "first section" (that is, section 1 in part I). How to fix that?

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}

\begin{document}

\tableofcontents
\part{Part I}
\section{The First One}   

\setcounter{section}{0}
\part{Part II}
\section{The Second One}

\end{document}

1 Answer 1

2

The simplest way to do this, that also happens to effect your choice of section numbering, is to add the section counter to those that are reset by \part. hyperref then automatically takes this into account when creating its anchors and links. The basic command to this is

\@addtoreset{section}{part}

As this command contains the @ character in its name, you need to wrap this in a \makeatletter...\makeatother pair.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{hyperref}

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

\begin{document}

\tableofcontents
\part{Part I}
\section{The First One}   

\clearpage
\part{Part II}
\section{The Second One}

\end{document}
2
  • Works fine, thanks. (And just to clarify: That is not my choice of section numbering. I more or less have to use this numbering mechanism.)
    – Keba
    Feb 11, 2015 at 20:35
  • 1
    \usepackage{chngcntr}\counterwithin*{section}{part} is cleaner.
    – egreg
    Feb 11, 2015 at 21:04

You must log in to answer this question.

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