2

I am using below code to create a document with clickable table of content and cross-references:

\documentclass[11pt,a4paper]{article}
\usepackage{lipsum}

\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{color,hyperref}
\definecolor{darkblue}{rgb}{0, 0, .7}

\hypersetup{colorlinks,
            breaklinks,
            linkcolor=darkblue, % color used for in-document links
            urlcolor=darkblue,
            anchorcolor=darkblue,
            citecolor=darkblue}

\title{Title here}
\author{Author, First Name}
\date{\today}


\begin{document}
\maketitle

\tableofcontents

\newpage

\section{Introduction} \label{sec:intro}
    \lipsum[2] The \textit{Section} \ref{sec:second} does things.

\section{Second section} \label{sec:second}
\lipsum[1]

\end{document}

I want different link colors for the links in the TOC (black) and for cross-references (darkblue). However changing linkcolor alters both. Is there a way to manipulate them separately?

1
  • So you want one color for in-document links when they are in the ToC and one for in-document links after the ToC?
    – TobiBS
    Commented Jun 9, 2020 at 15:39

1 Answer 1

3

If I understood you right, you want to have linkcolor change after the ToC, correct? Well just call \hypersetup a second time after the ToC was typeset:

\documentclass[11pt,a4paper]{article}
\usepackage{lipsum}

\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{color,hyperref}
\definecolor{darkblue}{rgb}{0, 0, .7}

\hypersetup{colorlinks,
            breaklinks,
            linkcolor=black, % color used for in-document links
            urlcolor=darkblue,
            anchorcolor=darkblue,
            citecolor=darkblue}

\title{Title here}
\author{Author, First Name}
\date{\today}


\begin{document}
\maketitle

\tableofcontents
\hypersetup{colorlinks,
    breaklinks,
    linkcolor=darkblue, % color used for in-document links
    urlcolor=darkblue,
    anchorcolor=darkblue,
    citecolor=darkblue}

\newpage

\section{Introduction} \label{sec:intro}
    \lipsum[2] The \textit{Section} \ref{sec:second} does things.

\section{Second section} \label{sec:second}
\lipsum[1]

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .