Text FormattingOverfull \hbox in URL

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
ghuczek
Posts: 23
Joined: Sun Dec 23, 2012 8:09 pm

Overfull \hbox in URL

Post by ghuczek »

I am having some trouble getting url's to hyphenate, to avoid the overfill \hbox situation.

Here is an example of a url I have in my .txt file:

Code: Select all

\url{http://www.who.int/water_sanitation_health/diseases/cholera/en/}
I am using \usepackage{url} in the preamble. Font size is 12 point, using the article document class.

The error message:

Code: Select all

Overfull \hbox (16.65001pt too wide) in paragraph
The url is too wide for the line and doesn't hyphenate.

The only workaround I have found is to use a smaller font size for the url by including the following in the preamble, which I found on Leo Breebart's site:
http://www.kronto.org/thesis/tips/url-formatting.html

Code: Select all

% Define a new 'leo' style for the package that will use a smaller font.
\makeatletter
\def\url@leostyle{%
	\@ifundefined{selectfont}{\def\UrlFont{\sf}}{\def\UrlFont{\footnotesize\ttfamily}}}
\makeatother
%% Now actually use the newly defined style.
\urlstyle{leo}
This works, but I am looking for something I might be able to use to keep the font size and style the same in the url's as in the rest of the document. Even using the smaller font size work-around above, if the url is too long I still end up with an overfull \hbox error.

Thanks in advance for any suggestions.
Last edited by cgnieder on Sun Jun 09, 2013 9:25 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Overfull \hbox in URL

Post by Johannes_B »

Hi, you gave us some information, this information would be much more helpful, if you would put them into a minimal working example using the code-button. This helps us to verify the problem and immediate testing is possible. Especially, since there is the Open in WriteLaTeX-Button.

Your workaround doesn't seem to be the best way right now.

Code: Select all

\documentclass{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}%able to do the same and even more

\begin{document}
\fbox{
\parbox{4cm}{
\url{http://theoval.cmp.uea.ac.uk/~nlct/latex/minexample/index.html}
}}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply