6

The quasi-MWE below uses the memoir class and works fine. It produces a document with the following structure:

  • ToC
  • Book
    • Part1
    • Chapter1
    • Part2
    • Chapter2
  • Index

Here, cross-references in the ToC and in the Index all work correctly. But I want to reset Chapter numbers back to "1" in each Part (and ultimately, in each Book, if there are many books). To do so, I uncomment the \counterwithin instructions in the preamble.

Now, depending on the value assigned to hyperref's hypertexnames option, I get the following behaviour:

  • if true, the ToC link to Chapter "2" in Part 2 (which is now renumbered to "1") does not works, but the Index link to AAAAA on page "5" does;

  • if false, the ToC link to Chapter "2" in Part 2 (which is now renumbered to "1") works, but the Index link to AAAAA on page "5" does not.

Am I doing something wrong?


\documentclass[a4paper,12pt]{memoir}

%\counterwithin*{chapter}{part}           % Restarts chapter count within Part.

\usepackage{hyperref}             
\hypersetup{
    hypertexnames=true,                
    linktocpage=false,
    colorlinks=true,                                        
}
\indexintoc
\makeindex[main]

\begin{document}
\frontmatter{}
\tableofcontents*
\mainmatter{}
\book{BookTitleA}
 \part{PartTitleA}
  \chapter{TitleA}
AAAAA\index[main]{AAAAA}.\\
 \part{PartTitleB}
  \chapter{TitleB}
BBBBB.
\backmatter
 \clearpage
 \printindex[main]
\end{document}
6
  • \documentclass[a4paper,12pt]{memoir} %\counterwithin*{chapter}{part} % Restarts chapter count within Part. \usepackage{hyperref} \hypersetup{ hypertexnames=true, linktocpage=false, colorlinks=true, } \indexintoc \makeindex[main] \begin{document} \frontmatter{} \tableofcontents* \mainmatter{} \book{BookTitleA} \part{PartTitleA} \chapter{TitleA} AAAAA\index[main]{AAAAA}. \part{PartTitleB} \chapter{TitleB} BBBBB. \backmatter \clearpage \printindex[main] \end{document} Commented Oct 19, 2011 at 19:45
  • My apologies for my formatting failures. Commented Oct 19, 2011 at 19:51
  • If you need to modify your original question, click on the edit and add the relevant code, rather than posting uncommented code in a comment. Once you're done, clean up the comments section be removing the non-relevant ones.
    – Werner
    Commented Oct 19, 2011 at 20:03
  • The latex code initially appeared mangled in my post. That's why I commented in order to fix it (I'll do what you suggest, from now on). However, I see that the code is now properly formatted, I just don't know why or how to ensure that it will be in future posts. Commented Oct 19, 2011 at 20:10
  • If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). You can use backticks ` to mark your inline code. The latter also holds for comments, as you already know.
    – Werner
    Commented Oct 19, 2011 at 20:12

1 Answer 1

11

Simply moving \counterwithin* after \hypersetup seems to solve the problem:

\usepackage{hyperref}             
\hypersetup{
    hypertexnames=true,                
    linktocpage=false,
    colorlinks=true,                                        
}
\counterwithin*{chapter}{part}
1
  • I was searching for this solution for many hours now. There are lots of different tipps, but this is the only solution which worked for me!
    – jrast
    Commented May 25, 2013 at 8:11

You must log in to answer this question.

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