60

I found that the link-color for TOC text is identical to the link-color for Figures and Tables. When I change the color to black in the TOC also the color for Figures/Tables citation etc. is changed.

Is there a way to separately set the colors inside the TOC and outside?

3
  • Is there any chance you can reduce the length of the question?
    – user10274
    Dec 28, 2012 at 17:58
  • @MarcvanDongen: Length of the title of the question: reduced, question itself: well, reworded but not shortened, but I think it is short enough, isn't it?
    – Stephen
    Dec 28, 2012 at 18:18
  • @Stephen Much better now.
    – user10274
    Dec 28, 2012 at 18:32

2 Answers 2

82

\hypersetup{linkbordercolor=black} before \tableofcontents changes the link colour to black (also for links to Figures and Tables occurring in the TOC). Enclosing \hypersetup and \tableofcontents in a group (either by enclosing in curly braces {...}or by using \begingroup\hypersetup...\tableofcontents\endgroup) keeps the change local. (Using "plain colour names" like black requires the xcolorpackage.)

If the colorlinks=true option of the hyperref package is used, \hypersetup{linkcolor=black} must be used instead of \hypersetup{linkbordercolor=black}.

MWE:

\documentclass{article}
\usepackage{xcolor}
\usepackage{hyperref}
\begin{document}
{\hypersetup{linkbordercolor=black}
% or \hypersetup{linkcolor=black}, if the colorlinks=true option of hyperref is used
\tableofcontents
}
% \hypersetup{linkbordercolor=red} 
% is not necessary because the colour is only changed in the group
\section{First Section starting at page \pageref{s1}\label{s1}}

\ref{s1}

\end{document}

compiled MWE

Because you are using "black" (and assuming your text is written in black) also

{\hypersetup{hidelinks}
\tableofcontents
}

would be possible, which would - well, hide the links in the TOC.

3
  • 1
    +1 you might be able to make it a local change by using \begingroup\hypersetup....\tableofcontents\endgroup
    – cmhughes
    Dec 28, 2012 at 17:43
  • @cmhughes: Yes, I was answering while developing the answer (me bad), had it grouped now by {}, but I'll include the alternative in the answer.
    – Stephen
    Dec 28, 2012 at 18:12
  • 2
    {\hypersetup{linkcolor=black} \tableofcontents } works perfectly. thanks!
    – KOF
    Dec 28, 2012 at 22:53
-1

You can also choose colors for your hyper references. Include this in your preamble and modify it according to your needs!

\usepackage{color}
\definecolor{Darkgreen}{rgb}{0,0.4,0}
\usepackage{hyperref}
\hypersetup{%
    pdfborder = {0 0 0},
    colorlinks,
    citecolor=red,
    filecolor=Darkgreen,
    linkcolor=blue,
    urlcolor=cyan!50!black!90
}
3
  • 7
    he doesnt just need to modify the link color, but he needs to do it locally, i.e. only for the TOC and not for all the document
    – SAAD
    Nov 20, 2014 at 15:22
  • 1
    This doesn't answer the question.
    – lblb
    Oct 6, 2017 at 19:53
  • May not answer the question, but was useful for me.
    – vy32
    Dec 29, 2020 at 1:30

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.