[Tex/LaTex] On the use of \titleofcontents to customize the table of contents

table of contentstitletoc

I use the following piece of code (titletoc package) to customize the "part entries" of my table of contents. Can you help me to push the page number to the right so that it is aligned with the other page numbers?

\titlecontents{part}[0pt]{
\protect\addvspace{15pt}%
}{}{\large\bfseries\partname{} }{$\;$\titlerule$\;$\large\bfseries\thecontentspage}[]

enter image description here


Complete working example

\documentclass{book}

\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern} 
\usepackage{titletoc}

\titlecontents{part}[0pt]{
\protect\addvspace{15pt}%
}{}{\large\bfseries\partname{} }{$\;$\titlerule$\;$\large\bfseries\thecontentspage}[]

\begin{document}

\tableofcontents

\part{Part 1}
\chapter{Chapter 1}
\section{Section 1.1}
\section{Section 1.2}
\chapter{Chapter 2}
\section{Section 2.1}
\section{Section 2.2}
\part{Part 2}
\chapter{Chapter 1}
\section{Section 1.1}
\section{Section 1.2}
\chapter{Chapter 2}
\section{Section 2.1}
\section{Section 2.2}
\end{document}

Best Answer

Is that what you want? Your code didn't reset chapter numbers at each new part, so I used the chngcntr package.

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\usepackage[english]{babel}
\usepackage{titletoc}
\usepackage{chngcntr}
\counterwithin*{chapter}{part}

\titlecontents{part}[0pt]{\large\bfseries\protect\addvspace{15pt}}%
{}{\partname{}}%
{\enspace\titlerule \contentspage}%

\begin{document}

\tableofcontents

\part{Part One}

\chapter{Chapter the First}
\section{Section 1.1}
\section{Section 1.2}

\chapter{Chapter the Second}
\section{Section 2.1}
\section{Section 2.2}

\part{Part Two}

\chapter{Chapter the First}
\section{Section 1.1}
\section{Section 1.2}

\chapter{Chapter the Second}
\section{Section 2.1}
\section{Section 2.2}

\end{document} 

enter image description here