[Tex/LaTex] Hyperref, \noappendicestocpagenum appendix option, and table of contents

appendicescross-referencinghyperreftable of contents

In my thesis, I am using both the appendix package and the hyperref package. When I get to the appendix, I use the following commands:

\appendix
\noappendicestocpagenum
\addappheadtotoc
\appendixpage

In the table of contents, hyperref is providing links on just the page numbers, using the linktocpage=true
option. There is no page number for the "Appendices" page displayed on the table of contents thanks to the \noappendicestocpagenum command; however, hyperref generates a small empty red box regardless. Is there a way to stop this box from forming?

Here is a minimal working example.

\documentclass{report}
\usepackage{appendix}
\usepackage[pdftex,linktocpage=true]{hyperref}

\begin{document}

\tableofcontents

\chapter{Chapter Name}
Here is my document.

\clearpage
\appendix
\noappendicestocpagenum
\addappheadtotoc
\appendixpage

\chapter{Appendix Name}
Here is my appendix.

\end{document}

Best Answer

In your instance, I would just redefine what \addappheadtotoc does (since you know the structure you will be working with):

\makeatletter
\renewcommand{\addappheadtotoc}{%
  \phantomsection
  \addtocontents{toc}%
    {\protect\contentsline{chapter}{\appendixtocname}{}{}}%
 }
\makeatother

Of course, appendix is written to manage working in a variety of settings, but knowing the framework you find yourself in, it is an easy and manageable change.

Here's a complete minimal example:

enter image description here

\documentclass{report}
\usepackage{appendix}% http://ctan.org/pkg/appendix
\usepackage[pdftex,linktocpage=true]{hyperref}% http://ctan.org/pkg/hyperref

\makeatletter
\renewcommand{\addappheadtotoc}{%
  \phantomsection
  \addtocontents{toc}%
    {\protect\contentsline{chapter}{\appendixtocname}{}{}}%
 }
\makeatother
\begin{document}

\tableofcontents

\chapter{Chapter Name}
Here is my document.

\clearpage
\appendix
\noappendicestocpagenum
\addappheadtotoc
\appendixpage

\chapter{Appendix Name}
Here is my appendix.

\end{document}
Related Question