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.

I need to use boxed links and ragged right text. The problem is that when a link spans two lines, though the link is broken correctly (when using pdflatex) the box around the linked text extends until the right margin. Consider the following example:

\documentclass{article}
\usepackage[textwidth=45mm]{geometry}
\usepackage[colorlinks=false]{hyperref}

\begin{document}
\raggedright
\href{http://www.ctan.org/}{The Comprehensive TeX Archive Network}
\end{document}

In the output, the link box extends beyond the end of 'TeX' and up to the right margin, thus enclosing some white space. Is there a way to make the box around the link extend only up to the end of the text and not the right margin?

share|improve this question
    
Related: Adjust box around hyperref footnote links (Compiling with XeLaTeX actually solves your problem, too.) –  Qrrbrbirlbel Nov 6 '12 at 2:23
    
Manual way: \href{http://www.ctan.org/}{The Comprehensive TeX} \href{http://www.ctan.org/}{Archive Network} –  Qrrbrbirlbel Nov 6 '12 at 2:32
    
@Qrrbrbirlbel: both solutions indeed work, but I was looking for a solution which works a) automatically and b) in pdflatex. –  ctef Nov 7 '12 at 14:55

1 Answer 1

Simplest is just to link each word separately. Probably if necessary one could prevent the acrobat link boxes from drawing the vertical lines between words, but perhaps this is enough?

enter image description here

\documentclass{article}
\usepackage[textwidth=45mm]{geometry}
\usepackage[colorlinks=false]{hyperref}

\makeatletter
\let\oldhref\href
\def\href#1#2{%
\def\hrlink{\oldhref{#1}}%
\hrrsp#2 \relax}

\def\hrrsp#1 #2{%
\hrlink{#1}%
\ifx\relax#2%
\expandafter\@gobbletwo
\else
\ %
\fi
\hrrsp#2}
\begin{document}
\raggedright
\href{http://www.ctan.org/}{The Comprehensive TeX Archive Network}
\end{document}
share|improve this answer

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.