[Tex/LaTex] trick to beautify bibliography

biblatexmemoirtypography

I'm using the memoir and biblatex packages together. In general, I'm very happy with both. However, in my bibliography, I get some overflows and I don't have any clue how to avoid them… are there packages / commands / settings / tricks to achieve a nice looking bibliography and avoid overflows as depicted below? I know that latex does its best about type setting, but maybe there are some pitfalls I'm not aware of. Thank you!

enter image description hereenter image description here

UPDATE
Using the block=ragged option avoids overflows, but also omits the text justification I like so much 🙂 (see next figure) So unfortunately, this is not an alternative.

enter image description here

Best Answer

As mentioned in the comments, microtype is your friend here, and produces nicer output for the rest of the document as well.

Because all of these options depend on your reference list/reference style/margin settings/font choices (which we do not have), I've listed a few options and compared them using a sample text (\lipsum) and sample reference list biblatex-examples.bib which should be included on any system with biblatex installed.

In addition to microtype, I'd recommend a setting for biblatex's block= option. cgnieder suggested block=ragged, but I think this will be not acceptable for you given the update to your question. I've included it for future visitors, though. :-)

I think block=space would look closer to your ideal output. It allows extra space to be inserted between "blocks" in the bibliography, which can alleviate would-be line-breaking problems.

Another option could be \RaggedRight from ragged2e, which enables hyphenation without full justification, but this didn't look the greatest either considering your dissatisfaction with the block=ragged option. But again, this is highly dependent on the text/font/margins, so I've included it as an option for future visitors to try.

MWE

Here's the base test MWE I used to compare the settings:

\documentclass[draft]{memoir} % `draft' to show overfull \hboxes
\usepackage{lipsum}
%\usepackage{ragged2e}
\usepackage[final]{microtype} % `final' to prevent disabling
\usepackage[
  backend=biber, % default, but avoids warnings
  block=space,   % allow additional horizontal space between blocks
%  block=ragged,  % set the bibliography ragged right and introduce a line break penalty
]{biblatex}
\addbibresource{biblatex-examples.bib} % bunch of sample entries

\begin{document}
\lipsum    % print the sample text
\nocite{*} % print all references in the bibliography

%\raggedright
%\Raggedright
\printbibliography
\end{document}

Spoiler alert: the "best" (IMHO and for my test input/references) combination is shown in the sample above.

Comparison

I've left out anything that's "too ragged" (except for the default result) based on your update above. From "worst" to "best":

  • Default configuration; no \raggedright, no \RaggedRight, no microtype, default block=none: 14 bad boxes, worst 26.46pt too wide enter image description here
  • Add microtype with default settings: 4 bad boxes, worst 8.09pt too wide
  • Add block=space in addition to microtype: 1 bad box, 1.12pt too wide enter image description here

I've shown the worst offender in the screenshots, but line breaks around long DOI/URL-like strings were also vastly improved. Two examples:

Before: enter image description here enter image description here After: enter image description here enter image description here

Notes

If for some reason you really want microtype enabled only in the bibliography (though I'd recommend to just use it throughout the document), you can use \microtypesetup{disable} and \microtypesetup{enable} at the appropriate places in your document, as detailed in this answer. These keys are still undocumented, but you can find the code in lines 4118–4128 of the current (v2.5a) package code (p. 125 of the v2.5a documentation).