6

How can I break hyperref URLs in a tabular environment. Consider the following example:

\documentclass{article}

\usepackage[colorlinks=true,linkcolor=black,anchorcolor=black,citecolor=black,menucolor=black,runcolor=black,urlcolor=black,bookmarks=true]{hyperref}
\usepackage{breakurl}

\begin{document}

\url{http://www.avery/long/url?zz/very/very/long/this/should/break/very/long/long.html}

\begin{tabular}{l l}
   A long url &
\url{http://www.avery/long/url?zz/very/very/long/this/should/break/very/long/long.html}

\end{tabular}


\end{document}

The first one breaks, the second one doesn't. The output looks like:

url

I am using pdflatex.

2 Answers 2

9

Use the p{10.0cm} column specification, which require a length. This makes the column able to have line breaks:

enter image description here

\documentclass{article}

\usepackage[colorlinks=true,linkcolor=black,anchorcolor=black,citecolor=black,menucolor=black,runcolor=black,urlcolor=black,bookmarks=true]{hyperref}
\usepackage{breakurl}

\begin{document}
\noindent
\url{http://www.avery/long/url?zz/very/very/long/this/should/break/very/long/long.html}

\noindent
\begin{tabular}{l p{10.0cm}}
   A long url &
\url{http://www.avery/long/url?zz/very/very/long/this/should/break/very/long/long.html}
\end{tabular}
\end{document}
6

The l column specification has no control over the column width and therefore doesn't break the URL properly. Either fix the column using a p{<len>} column specification (where <len> is a known TeX length), or use the tabularx package to fix the table width to some maximum:

Tabularx with URL

\documentclass{article}
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\usepackage[colorlinks=true,linkcolor=black,anchorcolor=black,citecolor=black,menucolor=black,runcolor=black,urlcolor=black,bookmarks=true]{hyperref}% http://ctan.org/pkg/hyperref
%\usepackage{breakurl}% http://ctan.org/pkg/breakurl

\begin{document}

\noindent\url{http://www.avery/long/url?zz/very/very/long/this/should/break/very/long/long.html}

\noindent\begin{tabularx}{\textwidth}{l X}
   A long url & \url{http://www.avery/long/url?zz/very/very/long/this/should/break/very/long/long.html}
\end{tabularx}

\end{document}​

hyperref loads the url package by default, which does a good job of breaking URLs.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .