37

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}
  • Welcome to TeX.SE! This sounds like an interesting question, but are you sure that you want such an output? Have you ever seen a document that uses so many different colours? It sounds like it might be a little overwhelming... – cmhughes Feb 17 '13 at 2:11
  • @golbasche, you may accept my post if you think it answers your question. – Umar Kalim Feb 18 '13 at 6:21
  • I know this output sounds ridiculous ;) However, I do not intend to make my document a rainbow of colors. I only chose these colors for an easy to see testing environment. I will choose more subtle colors and formats once I figure out how to change everything. Thanks! – Kevin Feb 19 '13 at 0:36
  • related: tex.stackexchange.com/questions/50747/… – craq Dec 28 '15 at 17:51
4

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.

36

The hyperref options can be configured using the \hypersetup command and colors are enabled by colorlinks=true.

A MWE is below. citecolor is set to gray. For the table of contents link colors, linkcolor is set to green before the \tableofcontents command. Similarly for the list of figures, linkcolor is set to red before the \listoffigures command. Later linkcolor is set to blue for the internal links.

I was unable to make the table of contents's sub-section links appear in orange color.

\documentclass{article}
\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[backref=true,backend=biber,natbib=true,hyperref=true]{biblatex}
\bibliography{refs}

\usepackage{hyperref}
\hypersetup{
     colorlinks   = true,
     citecolor    = gray
}
\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~\cite{cit2}. 
\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}
\nocite{*}

\printbibliography
\end{document}

Here is a screenshot of the output: enter image description here

  • Thank you Umar. You got me one step closer. I would concede the request with the color orange. However, I'd still like to change the colors of the backref links. – Kevin Feb 19 '13 at 0:38
  • 3
    Ah. It wasn't hard to figure out the last thing after looking at the code in more detail. I added \hypersetup{linkcolor=yellow} before \printbibliography and I got what I wanted. Thanks! – Kevin Feb 19 '13 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.