Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

First I just ignored the hyperref package and just wanted something that 'looked' like a link:

\underline{\color{Blue} http://soundcloud.com}

but I end up getting an underline about 3mm below the link, which looks extremely ugly. After loading hyperref, I messed about with the variables but there is no underline feature. The best I could do was get it in blue:

\hypersetup{colorlinks=true,urlcolor=blue}
\urlstyle{same}
\url{http://soundcloud.com}

Question: Can I get a blue, underlined link so that the line is directly underneath the text (with or without an actual hotlink)?

share|improve this question
1  
I think my answer to Url with fragments in bold should answer that. I also show underlined and colored URLs there (but not both in combination yet). –  Martin Scharrer Jul 16 '11 at 15:40
4  
Note that \underline is AFAIK thought for mathematic expressions only, which might explain the odd look for "normal" text. To underline text see the soul or ulem packages. –  Martin Scharrer Jul 16 '11 at 15:55
3  
The (under)line is moved down because of the fact that the characters stretch below the baseline. If you want a tighter underline, \smash the argument: \underline{\color{Blue}\smash{http://soundcloud.com}}. Does this work? –  Werner Jul 16 '11 at 16:08
    
@Werner: Very fast and neat little trick! I think I may use that as a quick solution. –  Fahad Sperinck Jul 16 '11 at 16:27
    
Here, you can access the documentation for the ulem package: mirror.math.ku.edu/tex-archive/macros/latex/contrib/ulem/… –  night owl Aug 14 '11 at 6:17

3 Answers 3

up vote 10 down vote accepted

If you don't use hyperref:

\documentclass{article}
\usepackage{color}
\usepackage[normalem]{ulem}
\usepackage{url}

\DeclareUrlCommand\ULurl{%
  \renewcommand\UrlFont{\ttfamily\color{blue}}%
  \renewcommand\UrlLeft{\uline\bgroup}%
  \renewcommand\UrlRight{\egroup}}

\begin{document}

\ULurl{http://foo.bar/%12%34}

\end{document}

If you use hyperref, you may want to click on the URLs:

\documentclass{article}
\usepackage{xcolor}
\usepackage[normalem]{ulem}
\usepackage{hyperref}
\hypersetup{colorlinks,urlcolor=blue}
%% or
% \hypersetup{colorlinks=false,pdfborder=000}

% hack into hyperref
\makeatletter
\DeclareUrlCommand\ULurl@@{%
  \def\UrlFont{\ttfamily\color{blue}}%
  \def\UrlLeft{\uline\bgroup}%
  \def\UrlRight{\egroup}}
\def\ULurl@#1{\hyper@linkurl{\ULurl@@{#1}}{#1}}
\DeclareRobustCommand*\ULurl{\hyper@normalise\ULurl@}
\makeatother

\begin{document}

\ULurl{http://foo.bar/%12%34}

\end{document}
share|improve this answer
    
+1 I keep forgetting about \hyper@normalise. –  Martin Scharrer Jul 16 '11 at 16:34
    
dear sir, I've noticed that the second example seems to work only with \uline. However, the ulem package also provides \uuline or \dotuline. But these commands result in an error: Limit controls must follow a math operator. \UL@onmath ...hrest \mathop {\kern \z@ #1}\limits \sb {\UL@leadtype \LA@hski... l.21 \ULurl{http://foo.bar/%12%34}. What's the reason for that? –  Sebastian Jul 24 at 9:20

my solution to this

\documentclass{article}
\usepackage[hidelinks]{hyperref}
\usepackage{xcolor,soul,lipsum}
\newcommand{\myul}[2][black]{\setulcolor{#1}\ul{#2}\setulcolor{black}}

\begin{document}
\section{To See}\label{tosee}
hello refer ~\ref{tosee}
\href{www.google.com}{\color{blue} \myul[blue] {GOOGLE}}
\end{document}
share|improve this answer

Here a adaption of my solution for Url with fragments in bold. The result it look nice to me. However the URL isn't a hyperlink anymore, i.e. I can't click on it.

\documentclass{article}

\usepackage{hyperref}
%% works with `url` only as well:
%\usepackage{url}

\usepackage{xcolor}
\usepackage[normalem]{ulem}
\useunder{\uline}{\ulined}{}%
\DeclareUrlCommand{\bulurl}{\def\UrlFont{\ttfamily\color{blue}\ulined}}

\begin{document}

\bulurl{http://www.example.com/blue%^&&*}

\url{http://www.example.com/blue%^&&*}  % for comparision

\end{document}

Result

share|improve this answer
    
\frenchspacing seems unnecessary. It is not used in url.sty since no spaces should be used in a URL. –  Leo Liu Jul 16 '11 at 16:16
    
@Leo: Correct. I just had it in because I got funny spacings around :, but this turned out to be caused by something else. –  Martin Scharrer Jul 16 '11 at 16:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.