35

How can I have underlined links with hyperref?

That means how to configure hyperref not to change the color of the printout but use underlined active links which are completely transparent in print.

The condition for an answer to be qualified would be not to make code changes in a local copy of the hyperref macros, working for linebraking/hyphenation of links in dvi/PS as well as PDF output, configuration for different dvi-drivers (e.g. pstricks.con). Options to specify underline color, linewidth, relative position/offset to baseline are a plus but functional not essential.

lockstep
  • 250,273
Nil
  • 351
  • 1
  • 3
  • 3

3 Answers3

28

You can try this:

\documentclass{article}
\usepackage[colorlinks=false,
            allbordercolors={0 0 0},
            pdfborderstyle={/S/U/W 1}]{hyperref}

\begin{document}

\url{blub.blub.blub}

\end{document}
Ulrike Fischer
  • 327,261
  • 2
    allbordercolors={0 0 0} breaks my document, and adding pdfborderstyle={/S/U/W 1} on its own has no effect... – Edward Newell Mar 15 '14 at 20:06
  • @EdwardNewell: allbordercolors is defined in version 2011/02/05 6.82a. Underlined links are not supported by all PDF viewers. See also section "Link border style" of hyperref's README. – Heiko Oberdiek Mar 15 '14 at 20:12
8

Underline URLs, citations, figures and section references:

\usepackage[pdfborderstyle={/S/U/W 1}]{hyperref}

Or, if creating a template document:

\usepackage[hidelinks]{hyperref} % Clickable URLs and cross-references.
\hypersetup{pdfborderstyle={/S/U/W 1}} % Underline links (non-printing).
% Comment out the line above to remove underlines from links.

Notes:

  • The link text is not coloured, only the underline is coloured.
  • Colour of underline depends on the type of link. (i.e. different colours for URLs, citations, figures etc.)
  • Underline is invisible when printed.

Edit: You can change the link underline colours like this:[1]

\usepackage{xcolor}            % specify colors by name (e.g. "red")
\usepackage{hyperref}          % clickable URls and cross-references
\hypersetup{
    pdfborderstyle={/S/U/W 1}, % underline links instead of boxes
    linkbordercolor=red,       % color of internal links
    citebordercolor=green,     % color of links to bibliography
    filebordercolor=magenta,   % color of file links
    urlbordercolor=cyan        % color of external links
}

There are many more customisation options. See [1].

See this answer if you want URLs to look like they do in a web browser.

3

I suggest you use my package href-ul:

\documentclass{article}
\usepackage{href-ul}
\begin{document}
Go to \href{https://www.google.com}{Google}!
\end{document}

It will make you a link just like in web, elegantly underlined :)

yegor256
  • 12,021
  • 1
    Unfortunately, the lines are printed on paper, which does not happen with the pdfborderstyle={/S/U/W 1} approach. – AlexG Jun 14 '21 at 11:23
  • @AlexG it is the original intent of this package: to print the lines both in PDF and on paper – yegor256 Sep 03 '23 at 06:42