[Tex/LaTex] Further customize color of hyperref links

colorhyperreflinks

I have tried to find a way to customize how internal links are colored, but I don't yet have the expertise in finding and redefining commands. In the LaTeX example below, I describe how I would like to change the colors of various links. Any ideas or examples are much appreciated.

\documentclass{article}

\usepackage[backref=true]{biblatex}
\begin{filecontents}{refs.bib}
@book{cit1,
title = {The backreferences should be yellow},
author = {Last, First}
}
\end{filecontents}
\bibliography{refs.bib}

\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[colorlinks=true,
            linkcolor=red,
            urlcolor=blue,
            citecolor=gray]{hyperref}

\begin{document}

\title{Title}
\maketitle
\tableofcontents
\listoffigures

\section{Table of content's links should be green}
\label{s1}
All text, captions, and section headers after the list of figures
should be black. The citation links should be gray.\autocite{cit1}
\subsection{Table of content's subsections links should be orange}
Internal links like this section link \ref{s1} 
or this figure link \ref{f1} should be blue.

\begin{figure}[h]
\caption{List of figures links red}
\label{f1}
\end{figure}

\printbibliography

\end{document}

Best Answer

For the question of changing the link colour of subsections in the table of contents, one can use the tocloft package:

\documentclass{article}
\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{hyperref}
\hypersetup{
     colorlinks   = true,
     citecolor    = gray
}

\usepackage{tocloft}

\renewcommand{\cftsubsecfont}{\normalfont\hypersetup{linkcolor=orange}}
\renewcommand{\cftsubsecafterpnum}{\hypersetup{linkcolor=green}}

\begin{document}

\title{Title}
\maketitle
\hypersetup{linkcolor=green}
\tableofcontents
\hypersetup{linkcolor=red}
\listoffigures
\hypersetup{linkcolor=blue}

\section{Table of content's links should be green}
\label{s1}
All text, captions, and section headers after the list of figures
should be black. The citation links should be gray.
\subsection{Table of content's subsections links should be orange}
Internal links like this section link \ref{s1} 
or this figure link \ref{f1} should be blue.
\section{Making sure section titles turn back to green}
This should be green again in the ToC.

\begin{figure}[h]
\caption{List of figures links red}
\label{f1}
\end{figure}

\end{document}

It requires a little fiddling to find which commands need to be changed to make the colour what is desired. More information on page 10 of the documentation. To keep the font the same, I had to find the standard definition, p. 30 of the documentation.

enter image description here

The tocloft package also deals with all sort of options to change the list of figures (and list of tables), meaning you may be able to set all your wishes in the preamble using this package.

Related Question