# Underful \hbox in bibliography caused by next bib entry

My bibliography causes the following warning in XeLaTeX:

Underfull \hbox (badness 1048) in paragraph at lines 11--16


That one is caused by the first bib entry. However, I can solve it by modifying the second bib entry!

A minimal example is:

\documentclass{scrreprt}
\usepackage{xltxtra}
\usepackage{polyglossia}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@book{Book1,
author = {Some Author},
title = {Some title title title title title title title title},
publisher = {Somepublisher},
year = {2000},
isbn = {978-0-12-179152-0},
url = {http://www.example.com/testtesttesttesttesttesttes},
}
@book{Book2,
author = {G and W},
year = {2008},
}
\end{filecontents}

\begin{document}
\nocite{Book1}
\nocite{Book2}
\bibliography{\jobname}
\end{document}

The underfull \hbox appears in the ISBN part of the first bib entry. However, if I change the second author from G and W to G (which shortens the label from GW08 to G08), the warning vanishes and the ISBN is broken differently.

Example 2:

\documentclass{scrreprt}
\usepackage{xltxtra}
\usepackage{polyglossia}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@book{Book1,
author = {Some Author},
title = {Some title title title title title title title title},
publisher = {Somepublisher},
year = {2000},
isbn = {978-0-12-179152-0},
url = {http://www.example.com/testtesttesttesttesttesttes},
}
@book{Book2,
author = {G},
year = {2008},
}
\end{filecontents}

\begin{document}
\nocite{Book1}
\nocite{Book2}
\bibliography{\jobname}
\end{document}

Questions:

1. Why is that? Why does the short name of the second bib entry influence some line break in the first bib entry?
2. How should I deal with that? How do I solve this LaTeX warning in a correct way?
• You will find that changing the author in the Book2 entry also changes the label "G08" vs "GW08". The labels control the right margin of the entries, you will note a very subtle shift in the alignment on the right hand side, that is because "G08" is shorter than "Aut00" which is shorter than "GW08". So if both G and W are present the longest label is "GW08" and the alignment is done using the length of this label, but if only G is present then the longest label is "Aut00" and that is used to set the indent. – moewe Sep 9 '15 at 9:26
• There is not a lot you can do about that. Line breaking in bibliographies is notoriously difficult, if you add other (more) items the problem might go away (if another label is longer and the indentation is changed). You can set your bibliography ragged right, allow for emergency stretches, ... – moewe Sep 9 '15 at 9:39
• @moeve: Why don't you propose your comments as answer? I would love to upvote and to accept them. – vog Sep 10 '15 at 16:53
• OK it has become a wall of text, but I hope it can help. – moewe Sep 11 '15 at 7:37

For general line breaking problems in biblatex bibliographies you may be interested in How to adjust the breaking in the bibliography?.

As you noted when changing the authors, the label changes as well. A change in the label can have some serious consequences though. This is because the bibliography is aligned using the length of the longest label, so everything looks nice and uniform and no label protrudes into the bibliography items.

In your case you have the labels "Aut00" and "G08" or "GW08". Out of "Aut00" and "G08" the former is the longest; but "GW08" is longer than "Aut00" (in the font in your example, anyway). So in one situation we use "Aut00" to align the entries and in the other "GW08" resulting in slightly different margins. It is this tiny change in the alignment that makes the line break algorithm not want to break the ISBN any more.

You will note that in the case where the breaking occurs the line is quite full already, the spaces compressed. By then adding to the margin using the longer label, we further reduce the space available in a line to the extent that a line break is no longer possible.

Solutions are not that easy to find in general, line breaking is difficult, but line breaking in bibliographies is notoriously difficult. Not all contents of bibliography items lend themselves to good hyphenation and line breaking results; line breaking works very well with large portions of homogeneous flowing text with many opportunities for breaks, less so with short portions of text sprinkled with unbreakable spaces.

The old trick of "rewrite your paragraph to allow for a nice line breaking" can hardly be applied to bibliographies. You can of course hope that another longer item comes along changing the margin again, maybe so much so that another line break becomes feasible.

A first try is often the microtype package which can do a lot. (It seems to resolve the issue in the MWE as well. But in some cases even microtype can't help.)

Then you can play around with allowing for an \emergencystretch or more, those options are then often set on an ad-hoc basis using try-and-error. You could even try and change the value of \labelsep temporarily, see Bibliography - Increase horizontal white space after each entry to make the output look OK.

Finally, you can choose to set your bibliography ragged right (How to prevent automatic justification of references?) so that space does not get stretched out.

• microtype saved me :) – BlackBrain Sep 12 at 8:04

To document how I solved this, I applied https://tex.stackexchange.com/a/10928 and added the following command before \begin{document}:

\apptocmd{\sloppy}{\hbadness 4000\relax}{}{}

• Did that actually change the output, though? I think I read somewhere that \hbadness only controls the warnings issued by TeX about bad boxes, not the actual typesetting result. – moewe Sep 14 '15 at 16:37
• @moewe: No, it doesn't change the output. But it removes warnings that are irrelevant for me (I'm not supposed to change the Bibliography style), so I can concentrate on those warnings that are worth fixing. – vog Sep 14 '15 at 16:48
• Mhh OK. Did you try loading microtype though, it works wonders. And a bit of fiddling with stretches is hardly changing the bibliography style. But if someone else is going to typeset the document (journal submission) that probably does not really matter. – moewe Sep 14 '15 at 17:12