15

I'm using moderncv and by default the links I set via \href{}{} seem to have the same color as normal text. How do I change their color?

I tried to add (according to How to change the color of \href links... for real):

\definecolor{links}{HTML}{2A1B81}
\hypersetup{colorlinks,linkcolor=,urlcolor=links}

The document failed building with

Undefined control sequence. l.33 \hypersetup 
{colorlinks,linkcolor=,urlcolor=links} 

Another failed try was:

\usepackage[colorlinks=true,linkcolor=black]{hyperref}

That gave the error:

LaTeX Error: Option clash for package hyperref.
Christian
  • 341
  • Are you really getting errors about undefined hypersetup or an error because links is not a valid color? – Johannes_B Oct 31 '15 at 11:43
  • @Johannes_B : I copied the error that the Overleaf console gave me. – Christian Oct 31 '15 at 11:46
  • @Christian: Is \hypersetup used before \usepackage{hyperref} ;-) –  Oct 31 '15 at 11:49
  • @ChristianHupfer It seems like \usepackage{hyperref} is used in the .cls and I try to use \hypersetup in the .tex – Christian Oct 31 '15 at 11:56
  • @Christian the proble is that hyperref is loaded with \AtEndPreamble so one can try \hypersetup{colorlinks,linkcolor=,urlcolor=links} after \begin{document} but I am not sure it will work. – touhami Oct 31 '15 at 11:59
  • PassOptionsToPackage – Johannes_B Oct 31 '15 at 12:07
  • 1
    This is another example of a template being smart but actually making it much more difficult for the user to change stuff. Fixed-output (given) vs. non-fixed output (what the op wants) – Johannes_B Oct 31 '15 at 12:08

1 Answers1

17

Here is a solution.

hyperref is loaded at the end of the preamble with \AtEndPreamble. We need to pass colorlinks,linkcolor=true options to the package, one way is to make it global \documentclass[colorlinks,linkcolor=true]{moderncv} and than \hypersetup{urlcolor=thecolor} after \begin{document}

MWE

\documentclass[11pt,a4paper,colorlinks,linkcolor=true]{moderncv}
\moderncvstyle{casual} 
\moderncvcolor{blue}
\name{Some}{One}
\title{some title} 
\address{10, address}{city}{Country}
\email{someone@myemail.com}
\homepage{www.mypage.com}

\begin{document}
\makecvtitle

\cventry{2015--2016}{Recherche}{Bla bla}{Foo bar}{More bla bla}%
{Last bla bla}

\cvitem{bla bla}{Foo bar}

\href{http://tex.stackexchange.com/q/275848/71471}{Defaut color}

\definecolor{links}{HTML}{2A1B81}
\hypersetup{urlcolor=links}
\href{http://tex.stackexchange.com/q/275848/71471}{Your color}

\end{document}
touhami
  • 19,520
  • Then to prevent links in your footer from being altered, add \hypersetup{hidelinks} before the \clearpage – Michael Jan 02 '18 at 22:25
  • 5
    I get an error with linkcolor=true while compiling, but e.g. linkcolor=cyan works alright. – Antti May 23 '19 at 07:10