247

If I use

\usepackage[colorlinks]{hyperref}

I get colored links for \cite (not good for printing or even viewing) but table of content looks fine.

If I use

\usepackage[colorlinks=false]{hyperref}

I get \cite links in black with a colored frame (this looks very good) but the table of content looks strange with extra long boxes.

What are my other options? Can you have two styles in different parts of a document?

How do you make the page numbers in TOC to be the links instead of the section headers?

3

3 Answers 3

369
+100

You can customise pretty much any thing in that regard, all the way to hiding all the links (no colours, no frames, just plain black text) with hidelinks.

if you use colorlinks=true you can set (defaults in []):

  • linkcolor [red]
  • anchorcolor [black]
  • citecolor [green]
  • filecolor [cyan]
  • menucolor [red]
  • runcolor [cyan - same as file color]
  • urlcolor [magenta]
  • allcolors -- use this if you want to set all links to the same color

if you want some of these not coloured, simply set them to . (e.g., citecolor=.), which will use the color of the text where the link appears.

if you use colorlinks=false and therefore want the frames around the links you have access to these settings:

  • citebordercolor [rgb 0 1 0]
  • filebordercolor [rgb 0 .5 .5]
  • linkbordercolor [rgb 1 0 0]
  • menubordercolor [rgb 1 0 0]
  • urlbordercolor [rgb 0 1 1]
  • runbordercolor [rgb 0 .7 .7]
  • allbordercolors

again if you want some of these to not appear, set them to white.

In your case, if you want the frames around links in citations but not on the table of content (and therefore not on other links such as to figures, tables or footnotes) I suggest you have a \hypersetup configuration with at least:

\usepackage{hyperref}
\hypersetup{
    colorlinks = false,
    linkbordercolor = {white},
    <your other options...>,
}
15
  • 19
    Thx! \hypersetup{ hidelinks = true, } worked for me to keep link functionality, but print them black (without frames)
    – OneWorld
    Sep 6, 2012 at 23:59
  • 4
    @OneWorld hidelinks does not take on any values. You just include the option or you don't. In particular, no Boolean modifier...
    – kan
    Oct 9, 2012 at 2:42
  • 3
    @Sampath: Thank you, I will consider that next time I use this command. However, as I remember the extra value did not break anything. So, for the record: \hypersetup{ hidelinks, } is correct.
    – OneWorld
    Oct 12, 2012 at 12:47
  • @DimitarAsenov: Is it possible to change the footnote color? :) Nov 25, 2016 at 9:24
  • 8
    @displayname See this answer tex.stackexchange.com/a/4506 e.g. urlcolor = [rgb]{0,0,0.5}. Jul 13, 2017 at 18:50
12

Very useful discussion. Thanks. Only one small comment

if you want some of these not colored, simply set them to . (e.g., citecolor=.), which will use the color of the text where the link appears.

I found (MiKTeX, current as of Feb 2019) that [linkcolor=] caused it to follow the text color, but [linkcolor=.] caused an error.

5
  • 1
    I can not confirm that, I'm using current MiKTeX and got no error. Can you please ask a new question (with an link to this one), adding an compilable tex code, the complete error message and your used OS?
    – Mensch
    Feb 28, 2019 at 3:14
  • OK, I'll try to do that.
    – Dr Darren
    Mar 4, 2019 at 23:01
  • 18
    I am curious as to why my little query was edited to spell 'colour' as 'color'. I am from a county that uses the 'u'. While I have to use 'color' when spelling LaTeX commands, I don't spell it that way when writing a general sentence. Is it a policy of this forum to enforce American spellings?
    – Dr Darren
    Apr 15, 2019 at 23:54
  • 4
    British spelling is also fine according to meta.stackoverflow.com/a/375197/1172409, so Stefan made an error.
    – miyalys
    Sep 17, 2019 at 9:23
  • Same for me on Overleaf, [citecolor=.] has the intended effect but gives errors, while [citecolor=] removes the errors.
    – Benitok
    Mar 10, 2021 at 18:51
1

ArTourter gave already an excellent answer.

To address your remaining questions:

Can you have two styles in different parts of a document?

Yes, e.g. if you don't want the boxes for the TOC, you can locally hide the links:

\begingroup
  \hypersetup{hidelinks}
  \tableofcontents
\endgroup

How do you make the page numbers in TOC to be the links instead of the section headers?

According to the manual, you have two options

option type default description
linktoc text section make text (section), page number (page), both (all) or nothing (none) be link on TOC, LOF and LOT
linktocpage boolean false make page number, not text, be link on TOC, LOF and LOT

So you can use

\usepackage[linktoc=page]{hyperref}

or variants of it. (You can also use it in the hypersetup, like in this answer)

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.