3

I'm trying to change the numbering for some chapters from numbers to letters, using:

\documentclass{report}
\setlength\parindent{0pt}
\usepackage{hyperref}
\begin{document}

Reference to chapter 1: \ref{chapter_1}

Reference to chapter A: \ref{chapter_a}

\chapter{A chapter}
\label{chapter_1}

\setcounter{chapter}{0}
\renewcommand{\thechapter}{\Alph{chapter}}%
\chapter{Another one}
\label{chapter_a}

\end{document} 

Of course, using \setcounter{chapter}{0}, I end up with two chapters "1", one denoted as a number, the other as a letter, which messes up the clickable references from hyperref (in the example above, both clickable references lead to the first chapter).

Is there a way to solve that -- change one chapter to use a letter instead of a number, without messing up the references by resetting the chapter number?

Bart
  • 247
  • Your question can be solved by adding the option 'hypertexnames=false' to hyperref. But, this has alredy been asked here on TeX.SX. – Ruben Apr 17 '16 at 19:04

2 Answers2

1

Just add option \usepackage[hypertexnames=false]{hyperref}

\documentclass{report}
\setlength\parindent{0pt}
\usepackage[hypertexnames=false]{hyperref}
\begin{document}

Reference to chapter 1: \ref{chapter_1}

Reference to chapter A: \ref{chapter_a}

\chapter{A chapter}
\label{chapter_1}

\setcounter{chapter}{0}
\renewcommand{\thechapter}{\Alph{chapter}}%
\chapter{Another one}
\label{chapter_a}


\end{document} 

option [hypertexnames=false] allows to use hyperrref's counters, but not TeX ones corresponding to \usepackage{hyperref}, which is actually \usepackage[hypertexnames=true]{hyperref}

Olga K
  • 981
1

Another possibility: Use \renewcommand{\theHchapter}{otherchapter\thechapter} to prevent the doubled chapter counter values which confuses hyperref, because this sets the link anchors.

\documentclass{report}
\setlength\parindent{0em}
\usepackage{hyperref}
\begin{document}

Reference to chapter 1: \ref{chapter_1}

Reference to chapter A: \ref{chapter_a}

\chapter{A chapter}
\label{chapter_1}


%\appendix
\setcounter{chapter}{0}

\renewcommand{\thechapter}{\Alph{chapter}}%
\renewcommand{\theHchapter}{otherchapter\thechapter}
\chapter{Another one}
\label{chapter_a}

\end{document}