283

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?

m0nhawk
  • 9,664
Maesumi
  • 9,059

3 Answers3

432

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...>,
}
ArTourter
  • 17,315
  • 27
    Thx! \hypersetup{ hidelinks = true,
    } worked for me to keep link functionality, but print them black (without frames)
    – OneWorld Sep 06 '12 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 09 '12 at 02: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 '12 at 12:47
  • @DimitarAsenov: Is it possible to change the footnote color? :) – Hosein Rahnama Nov 25 '16 at 09:24
  • @H.R. I assume you mean the footnote marker? Perhaps this can help: http://tex.stackexchange.com/questions/26693/change-the-color-of-footnote-marker-in-latex I'm not aware of a hyperref option to do this, but I'm not at all experienced with that package. On a side note, I personally leave footnotes the same color as the text, because a footnote is supposed to be just some inessential additional information (if it is essential, don't make it a footnote), and as such it is best if the footnote marker/text does not draw attention, and is easy to skip. A different color will draw more attention. – Dimitar Asenov Nov 25 '16 at 09:33
  • Thank you; it is incredibly difficult to find the documentation on this for whatever reason. – Luke Davis May 07 '17 at 22:06
  • Could you explain how it is possible to create a custom color? E.g. linkcolor = [1, 0, 0] % rgb. What's the syntax for setting a custom color like this? – Stefan Falk Jun 27 '17 at 13:28
  • 8
    @displayname See this answer https://tex.stackexchange.com/a/4506 e.g. urlcolor = [rgb]{0,0,0.5}. – Ponkadoodle Jul 13 '17 at 18:50
  • @OneWorld Did you find out how you made those red frames printable? – Lars Abrahamsson Jul 28 '18 at 20:10
  • @ArTourter: It is possible having for example URL links as colorlinks = true, but "links" as cololinks = false? – Lars Abrahamsson Jul 28 '18 at 20:12
  • @LarsAbrahamsson the colour frame should not be printable and there is no real way to make them. However, some pdf viewer don't support this feature of pdf and print them anyway. I haven't found a way of having both colorlinks and pdfborder on the same document: if colorlinks is set to true, then it set pdfborder to 0 0 0, but if you don't explicitly set colorlinks, then setting colours is ignored. – ArTourter Aug 04 '18 at 17:23
  • I am using \usepackage[pagebackref,colorlinks=true,linkcolor=.,]{hyperref} to hide all the links, I had read box everywhere, I just want that on the cite and on the backref, however the backref is considered as links, so they got hidden too. Does anyone knows a work around? – Eduardo Reis Aug 08 '20 at 10:31
  • @EduardoReis you probably want to ask a separate question for you problem with more details on what you are trying to achieve. – ArTourter Aug 10 '20 at 17:30
  • @ArTourter what is the "right" way to have any links in the document in the same colour as the text? Is there an easier way, or do I have to set colorlinks = false and then everything else to white? – EtoAls Aug 12 '20 at 21:12
  • @EtoAls probably the easiest way is using hidelinks as described at the beginning of the answer. however, that will not let you setting any exception. – ArTourter Aug 13 '20 at 12:28
  • One question please: are these colors displayed in the printed version of the file? – Wallflower Apr 17 '23 at 11:05
  • 1
    @Wallflower when colorlinks=true then yes, the colors are part of the text and printed. When colorlinks=false it depends on the viewer used to print the document. In theory, the links' border should not be printed but some viewers do not handle them properly and print them anyway. When i want to make a print only version, i usually compile a new one with either hidelinks or hyperref disabled entirely. – ArTourter Apr 21 '23 at 11:17
  • @ArTourter Understood, thank you very much! – Wallflower Apr 22 '23 at 17:08
13

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.

Stefan Pinnow
  • 29,535
Dr Darren
  • 179
  • 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 '19 at 03:14
  • OK, I'll try to do that. – Dr Darren Mar 04 '19 at 23:01
  • 22
    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 '19 at 23:54
  • 5
    British spelling is also fine according to https://meta.stackoverflow.com/a/375197/1172409, so Stefan made an error. – miyalys Sep 17 '19 at 09:23
  • Same for me on Overleaf, [citecolor=.] has the intended effect but gives errors, while [citecolor=] removes the errors. – Benitok Mar 10 '21 at 18:51
  • For citecolor=. you need \usepackage{xcolor}. – user691586 Feb 13 '24 at 14:01
9

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)

DerWeh
  • 320