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.

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.

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

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}
share|improve this answer
add comment

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.

share|improve this answer
add comment

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.