49

I am getting lots of "Underfull \hbox" warnings that point to the *.bbl file. It looks like these messages appear only when URLs are very long, like in the below example:

@techreport{nistguidesec,
  author    = {Wayne Jansen and Timothy Grance},
  title     = {Guidelines on Security and Privacy in Public Cloud Computing},
  month    = {January},
  note     = {Draft Special Publication 800-144. Available at \url{http://csrc.nist.gov/publications/drafts/800-144/Draft-SP-800-144_cloud-computing.pdf}},
}

In the produced PDF text is correctly hyphened and links are correctly split over several lines (I am using hyperref package)

How can I avoid annoying warning messages about "underfull \hbox" pointing to bibliography?

lockstep
  • 250,273
oldbam
  • 593
  • 1
  • 4
  • 4

1 Answers1

48

Because "line-breaking in the bibliography is often more difficult than in the body text" (biblatex manual, p. 91), LaTeX typesets the bibliography using the \sloppy macro which relaxes some of TeX's parameters/penalties for line-breaking. However, \sloppy (maybe for some good reason!) does not touch \hbadness which is (among other things) responsible for "Underfull \hbox" warnings. The following code (to be added to your preamble) appends \hbadness 10000 to \sloppy which should remove those warnings.

\usepackage{etoolbox}
\apptocmd{\sloppy}{\hbadness 10000\relax}{}{}

Alternatively (and without possible adverse affects), you could typeset the bibliography \raggedright:

\usepackage{etoolbox}
\apptocmd{\thebibliography}{\raggedright}{}{}

Minimal example (compilable):

\documentclass{article}

\textwidth 300pt

\usepackage{etoolbox}
% Variant A
\apptocmd{\sloppy}{\hbadness 10000\relax}{}{}
% Variant B
% \apptocmd{\thebibliography}{\raggedright}{}{}

\usepackage{hyperref}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@techreport{nistguidesec,
  author    = {Wayne Jansen and Timothy Grance},
  title     = {Guidelines on Security and Privacy in Public Cloud Computing},
  month    = {January},
  note     = {Draft Special Publication 800-144. Available at \url{http://csrc.nist.gov/publications/drafts/800-144/Draft-SP-800-144_cloud-computing.pdf}},
}
\end{filecontents}

\begin{document}

\nocite{*}

\bibliographystyle{plain}
\bibliography{\jobname}

\end{document}

(The filecontents environment is only used to include some external files directly into the example, so that it compiles. It is not necessary for the solution.)

lockstep
  • 250,273
  • 1
    IMHO it should be \apptocmd{\sloppy}{\hbadness 10000\relax}{}{}, just to be sure. Or use \@M for 10000 if \makeatletter is already in affect. – Martin Scharrer Feb 12 '11 at 18:22
  • 1
    @Martin: I corrected my code samples to include \relax. – lockstep Feb 12 '11 at 18:27
  • 3
    Alternatively, you could have just put a space after the number. Since you mention \raggedright, it's probably worth mentioning that \RaggedRight from ragged2e is almost certainly a better choice. – TH. Jun 25 '11 at 10:06
  • 4
    Why is this preferred to say \begingroup \hbadness 10000\relax \printbibliography \endgroup? I tried \apptocmd{\sloppy}{\hbadness 10000\relax}{}{} but it had no effect. – Andrew Bate Feb 02 '17 at 20:01
  • @AndrewBate one reason may be that it allows you to separate style from content, as you can amend \sloppy in the preamble. (Of course, you could also amend \printbibliography in the preamble.) Another reason may be that you may not want to change bibliographies that do not use \sloppy... – bers Feb 05 '21 at 09:36
  • In my case, the bibliography is messed up by splitting the words apart trying to fill the whole line and accommodate for the long URL that follows, so raggedright is the solution. ```latex \begin{raggedright} \bibliography{Bibliography} \end{raggedright}
    
    
    – Steven He Mar 30 '23 at 13:06