# ToC - add manual prefix “Part” to hyperref

I successfully added the prefix "Part" to my toc following this answer. However, it is not included in the hyperlink to that part of the document. Here is a MWE:

\documentclass[a4paper,twoside,openright,12pt]{book}
\usepackage[paper=a4paper]{geometry}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage[onehalfspacing]{setspace}

\usepackage{titletoc}

\titlecontents{part}
{}{\partname~}
{}

% setting hyperref colors

\begin{document}

\setcounter{tocdepth}{2}
\tableofcontents
\part{This is one part}
\chapter{With its first chapter}
\chapter{And its second}
\part{This is the second part}
\chapter{And another chapter}
\section{with a little section}
\end{document}


Which produces the following toc: As can be seen by the colors the link does start at the roman number and not at the prefix. Is there any way to include the prefix in the link as well?

• hyperrefdoes not know that there is a prefix. – user31729 Jan 10 at 14:23

Here are three solutions.

With etoc package this solution don't use titletoc but etoc.

\documentclass[a4paper,twoside,openright,12pt]{book}
\usepackage[paper=a4paper]{geometry}
\usepackage[english]{babel}
\usepackage{hyperref}
\usepackage[onehalfspacing]{setspace}

\usepackage{etoc}

\newcommand{\mytableofcontents}{%
\etocsetstyle{chapter}{}{}
{\etocsavedchaptertocline{\numberline{\etocnumber}\etocname}{\etocpage}}{}
\etocsetstyle{section}{}{}
{\etocsavedsectiontocline{\numberline{\etocnumber}\etocname}{\etocpage}}{}
\etocsetstyle{subsection}{}{}
{\etocsavedsubsectiontocline{\numberline{\etocnumber}\etocname}{\etocpage}}{}
\etocstandarddisplaystyle
\etocsetnexttocdepth{2}
\tableofcontents}}

\begin{document}

\mytableofcontents
\part{This is one part}
\chapter{With its first chapter}
\chapter{And its second}
\part{This is the second part}
\chapter{And another chapter}
\section{with a little section}
\end{document}


In tne next two solutions \partname had been removed from \titlecontents{part}

Patching \contentsline

\documentclass[a4paper,twoside,openright,12pt]{book}
\usepackage[paper=a4paper]{geometry}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage[onehalfspacing]{setspace}

\usepackage{titletoc}

\titlecontents{part}
{}{}
{}

% setting hyperref colors
\usepackage{etoolbox}
\makeatletter
\makeatother

\begin{document}
\setcounter{tocdepth}{2}
\tableofcontents
\part{This is one part}
\chapter{With its first chapter}
\chapter{And its second}
\part{This is the second part}
\chapter{And another chapter}
\section{with a little section}
\end{document}


Patching \addcontentsline

\documentclass[a4paper,twoside,openright,12pt]{book}
\usepackage[paper=a4paper]{geometry}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage[onehalfspacing]{setspace}

\usepackage{titletoc}

\titlecontents{part}
{}{}
{}

% setting hyperref colors
\usepackage{etoolbox}
\newcommand{\intocpartname}{}

\begin{document}
\setcounter{tocdepth}{2}
\renewcommand{\intocpartname}{\partname~}
\tableofcontents
\part{This is one part}
\chapter{With its first chapter}
\chapter{And its second}
\part{This is the second part}
\chapter{And another chapter}
\section{with a little section}
\end{document}

• @CaptainNabla you're welcome :-) – touhami Jan 11 at 8:09