I am using a code in tikz for a fancy table of contents and I want to apply certain settings on it using the hyperref package and the relevant command hyperrefsetup. I want to create the following image

or at least something that will be smooth, like section numbers should have the same color with their title and their page numbering while the chapter title should have this light blue color.

When I use linkcolor option(which I actually need it for colored links) there seems to be a mess up, where all of the ToC entries have the same color and not the same color with section/chapter/page numbering, like the following

or

How can I achieve the first image and how can I explicitly change section/page numbering color?

My code is the following

\documentclass{book}

\usepackage{tikz}

%~~~~~~~~~~~~~~~~~~~~~Fancy ToC~~~~~~~~~~~~~~~~~~~~~~
\usepackage{titletoc}
\usepackage{titlesec}

\definecolor{doc}{RGB}{0,60,110}
\definecolor{myblueii}{RGB}{63,200,244}

\contentsmargin{0cm}
\titlecontents{chapter}[0pc]
\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=myblueii,draw=myblueii, rounded corners] (-4,-.1) rectangle (-0.15,.5);%
\pgftext[left,x=-2.7cm,y=0.2cm]{\color{white}\Large \chaptertitlename\ \thecontentslabel};%
\end{tikzpicture}\color{myblueii}\large\bfseries}%
{}
{}
{\hspace*{6pt}\titlerule\hspace*{6pt}\large\bfseries \thecontentspage
\begin{tikzpicture}[remember picture, overlay]
\draw[fill=doc!25,draw=myblueii, rounded corners=0pt] (2pt,0) rectangle (6,0.1pt);
\end{tikzpicture}}%
\titlecontents{section}[2.4pc]
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\hfill\small \thecontentspage}
[]
\titlecontents{subsection}[4.8pc]
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\hfill\small\thecontentspage}
[]

\makeatletter
\renewcommand{\tableofcontents}{%
\chapter*{%
\vspace*{-20\p@}%
\begin{tikzpicture}[remember picture, overlay]%
\pgftext[right,x=15cm,y=0.2cm]{\color{myblueii}\Huge \contentsname};%
\draw[fill=myblueii,draw=myblueii, rounded corners=15pt] (13,-.75) rectangle (20,1);%
\clip (13,-.75) rectangle (20,1);
\pgftext[right,x=15cm,y=0.2cm]{\color{white}\Huge \contentsname};%
\end{tikzpicture}}%
\@starttoc{toc}}
\makeatother

%~~~~~~~~~~~~~~~~~Hyperref Settings~~~~~~~~~~~~~~~~~~~~~~

\usepackage{hyperref}
\hypersetup{%
pdfborder = {0 0 0},
citecolor=red,
filecolor=green,
urlcolor=cyan!50!black!90
}

%~~~~~~~~~~~~~~~~~Main Document~~~~~~~~~~~~~~~~~~~~~~~

\begin{document}
\tableofcontents
\chapter{rkbnjg}
\section{ljkihb;kjb}
\section{lkhb;hkb}
\section{;kjbkjb}
\subsection{;kjblkhjblhkb}
\subsection{lhjbljh}
\subsection{;jbnlkhjblbh}
\section{ljhblkhbj}
\subsection{ljhblhjkblkbh}
\chapter{kgjb}
\chapter{;kjdfb543}
\end{document}

• do you need links in your document to be coloured? since if i comment out all of colorlinks, citecolor=red, filecolor=green, linkcolor=myblueii from your MWE I get exactly the result you show in your first picture. Aug 13 '14 at 11:31
• @greyshade : Thank you very much for your comment! I know that when you comment colorlinks I get the behaviour that I want, but in fact I do need to have colored link in my document Aug 13 '14 at 11:36
• you might state that in your question somewhere;) Aug 13 '14 at 11:38
• @greyshade : I will, right now! Sorry for the inconvenience! Aug 13 '14 at 11:49

As mentioned in the comments, with all the link colouring commented out, you get the correct result. Thus, locally use the hidelinks option when the \tableofcontents is evoked (inspired by this). I.e. write:

{
\tableofcontents%
}


The complete code then should be:

\documentclass{book}

\usepackage{tikz}
\usepackage{titletoc}
\usepackage{titlesec}
\usepackage{hyperref}
%
\definecolor{doc}{RGB}{0,60,110}
\definecolor{myblueii}{RGB}{63,200,244}

%~~~~~~~~~~~~~~~~~Hyperref Settings~~~~~~~~~~~~~~~~~~~~~~
\hypersetup{%
pdfborder = {0 0 0},
citecolor=red,
filecolor=green,
urlcolor=cyan!50!black!90
}

%~~~~~~~~~~~~~~~~~~~~~Fancy ToC~~~~~~~~~~~~~~~~~~~~~~
\contentsmargin{0cm}
\titlecontents{chapter}[0pc]
\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=myblueii,draw=myblueii, rounded corners] (-4,-.1) rectangle (-0.15,.5);%
\pgftext[left,x=-2.7cm,y=0.2cm]{\color{white}\Large \chaptertitlename\ \thecontentslabel};%
\end{tikzpicture}\color{myblueii}\large\bfseries}%
{}
{}
{\hspace*{6pt}\titlerule\hspace*{6pt}\large\bfseries \thecontentspage
\begin{tikzpicture}[remember picture, overlay]
\draw[fill=doc!25,draw=myblueii, rounded corners=0pt] (2pt,0) rectangle (6,0.1pt);
\end{tikzpicture}}%
\titlecontents{section}[2.4pc]
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\hfill\small \thecontentspage}
[]
\titlecontents{subsection}[4.8pc]
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\hfill\small\thecontentspage}
[]

\makeatletter
\renewcommand{\tableofcontents}{%
\chapter*{%
\vspace*{-20\p@}%
\begin{tikzpicture}[remember picture, overlay]%
\pgftext[right,x=15cm,y=0.2cm]{\color{myblueii}\Huge \contentsname};%
\draw[fill=myblueii,draw=myblueii, rounded corners=15pt] (13,-.75) rectangle (20,1);%
\clip (13,-.75) rectangle (20,1);
\pgftext[right,x=15cm,y=0.2cm]{\color{white}\Huge \contentsname};%
\end{tikzpicture}}%
\@starttoc{toc}}
\makeatother

%~~~~~~~~~~~~~~~~~Main Document~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}
{
\tableofcontents%
}
\chapter{rkbnjg}
\section{ljkihb;kjb}
\section{lkhb;hkb}
\section{;kjbkjb}
\subsection{;kjblkhjblhkb}
\subsection{lhjbljh}
\subsection{;jbnlkhjblbh}
\section{ljhblkhbj}
\subsection{ljhblhjkblkbh}
\chapter{kgjb}
\chapter{;kjdfb543}
\end{document}


which outputs:

• Thank you very much for your answer! Although, it works for me, I think it would be very educational to do the coloring, separately for (sub)section numbers, titles and pages. Aug 13 '14 at 11:58