2

I have parts for each year:

\part{2011}
...
\part{2012}
...
etc.
...

I want the chapter number to be the month of that year for stylistic purposes (e.g. like how the chapter number is shown here)

\setcounter{chapter}{7}
\chapter{August 2011}

But now in the ToC the link for the "August 2011" chapter points to the page for "August 2010". How can I fix this?

  • 1
    Did you compile the main file twice? – Sigur Dec 8 '14 at 11:18
  • 1
    Can you please provide a full minimal working example (MWE) both in order to demonstrate what you are trying to do and to help others help you. The MWE should look like \documentclass...\begin{document}...\end{document}, it should compile and contain close to the minimal amount of code needed to explain/demonstrate what you are asking. This saves everyone time:) – Andrew Dec 8 '14 at 11:22
  • I guess the problem is the resetting of the chapter number from (12) to 1 for the next part (corresponding to a new year) this confuses hyperref -- however, the resetting is not done by default! – user31729 Dec 8 '14 at 13:23
  • 1
    I guess one could append the year to the hyperref-label making it unique. – Johannes_B Dec 8 '14 at 13:39
1

The resetting of the chapter counter after a new part (= year) confuses the hyperlink settings from hyperref in some cases unless the option hypertexnames=false is used.

This 'solution' uses an automatic setup of month names in loop, but it's not suited of course in this form for a productive run with content between the month chapters

\documentclass{scrbook}

\usepackage{forloop}
\usepackage{assoccnt}%
\usepackage{datetime}

\usepackage{hyperref}

\usepackage{bookmark}

\hypersetup{%
  hypertexnames=false
}%

\newcounter{monthloopcounter}
\newcounter{yearcounter}
\setcounter{yearcounter}{2009}

\DeclareAssociatedCounters{part}{yearcounter}



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



\begin{document}
\tableofcontents

\part{\theyearcounter}

\forloop{monthloopcounter}{1}{\value{monthloopcounter} < 13}{%
  \chapter{\monthname[\number\value{monthloopcounter}] \theyearcounter}%
}%


\part{\theyearcounter}

\forloop{monthloopcounter}{1}{\value{monthloopcounter} < 13}{%
  \chapter{\monthname[\number\value{monthloopcounter}] \theyearcounter}%
}%


\part{\theyearcounter}

\forloop{monthloopcounter}{1}{\value{monthloopcounter} < 13}{%
  \chapter{\monthname[\number\value{monthloopcounter}] \theyearcounter}%
}%

\end{document}

I used assoccnt package to add a co-marching counter which is updated each time a new \part is used.

enter image description here

  • hypertexnames=false works fine, thank you! – wrongusername Dec 9 '14 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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