I've got a document where I'd like two colours of links - cyan for links in headers that since it's brighter, and navy blue for links in the main body which is more subtle/less distracting. I already tried using the xcolor package and changing the text colour with textcolor, like \textcolor{cyan}{\href{url.com}{link name}}, but it doesn't override whatever link or url colour I have defined in hypersetup.

So this is what I've done:

I've defined the colour navy:


And also imported the hyperref package and defined commands to set the global link/url colours to cyan / navy.


Then I've defined another command specifically for the header links, where I turn on cyan links globally, include the header text and link, and then turn on navy links again:


My issue with this is that I feel like there could be a better way to do it than to set the global link colour every time I use a link macro; is there a way to define the link colour just for one link, like one would do with \textcolor{...}, that would be able to override hypersetup?


3 Answers 3


Preliminary remarks:

  • I would not change the link color inside headers. I think, it is more confusing than improving the readability.
  • URLs inside chapter/section/... titles are a little debatable.
  • My interpretation of "headers" are section titles inside the text, where the title is printed in larger font size and bold. But links in head lines or the table of contents use the normal text link color.

Instead of different commands, I would change the behavior at such places, where the links should display differently. In case of \section (and \subsection, ...) titles, a good place is \@sect, where the eighth argument contains the section title. The seventh argument is used for the table of contents and the head lines.



\usepackage[colorlinks]{hyperref}[2011/02/05]% option allcolors




% Test document that tries to put all cases in one page
\section{First chapter with URL
Link inside text: \href{http://tex.stackexchange.com/}{TeX.SE}.



  • There is a new option allcolors (and allbordercolors), that can be used as shortcut to set all color types (link, url, file, …) to the specified color (since hyperref 2011/02/05 v6.82a).

Make sure you using the xcolor package. Then define a color you want the hyperref setup to refer to. Then in the headers simply redefine this color using, say, \colorlet{mylinkcolor}{myheaderlinkcolor}.

Here is an example






(Had a look at one of my own constructions, turnes out, I did the same as you, reissued \hyperretup, but the example above show that the color is just a reference.


I would just use the \color macro inside the \href instead of outside, i.e. \href{url.com}{\color{cyan}{link name}}.





\color{red}{This is red text, \href{http://example.com}{but the links are still blue}.}

\href{http://example.com}{\color{red}{This is a red link.}}


You must log in to answer this question.

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