35

How to avoid using \sloppy document-wide to fix overfull \hbox problems?

overfull \hbox

This is my minimal working example.

\documentclass[12pt]{report}
 \usepackage[english,ngerman]{babel}
 \usepackage[a4paper,inner=25mm,outer=25mm,top=30mm,bottom=30mm]{geometry}
 \usepackage{lipsum}

 \begin{document}
  \lipsum[2]
  Have a look at this URL ignoring the page margin within the text flow \textit{example.com/donc\_oe/longurl} lorem ipsum.\par
  The very strange plugin Java-JDT (\textit{en. Java Development Toolkit}) "`Plugin-Entwicklungsumgebung"' -- what's wrong with this german word?\par
  \lipsum[2]
 \end{document}

With \sloppy it looks better.

enter image description here

But I got told it's (obviously) better to avoid using it document-wide. What else can I do?

  • 3
    For the first one, you could use \url from the url package. – Gonzalo Medina Jun 8 '12 at 21:21
  • 1
    You should be saying \usepackage[ngerman]{babel}; so input the offending long word as Plugin"-Entwicklungsumgebung, using the "- shorthand: a hyphen allowing hyphenation in the rest of the word. – egreg Jun 8 '12 at 21:41
  • 2
    Nobody suggests microtype? That won't help you there but it is always good to consider when typing text – topskip Jun 8 '12 at 22:06
  • 1
    The word "Plugin-Entwicklungsumgebung" should be written as Plugin"=Entwicklungsumgebung – topskip Jun 8 '12 at 22:27
17
  • When typesetting URLs, use the url package, since it provides adequate line-breaking support. If needed, you can change the typeface it uses in its display (default is \ttfamily).

  • Words not covered by default hyphenation (or that provided by babel can be incorporated in an ad-hoc way using \- or globally using \hypenation{<this-is-an-awk-ward-ly-long-word>}.

enter image description here

\documentclass[12pt]{report}
\usepackage[english,ngerman]{babel}% http://ctan.org/pkg/babel
\usepackage[a4paper,inner=25mm,outer=25mm,top=30mm,bottom=30mm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{url}% http://ctan.org/pkg/url
\begin{document}
\lipsum[2]
Have a look at this URL ignoring the page margin within the text flow \url{example.com/donc_oe/longurl} lorem ipsum.\par
The very strange plugin Java-JDT (\textit{en. Java Development Toolkit}) "`Plugin-Ent\-wick\-lungs\-umge\-bung"' -- what's wrong with this German word?\par
\lipsum[2]
\end{document}
  • 1
    If you write Plugin"=Entwicklungsumgebung the second problem should go away by itself. It is always good to write "= instead of - on long German words with -. – topskip Jun 8 '12 at 22:32
30

Also, you might want to set

\setlength{\emergencystretch}{2pt}

or something similar. Explanation: if TeX can't typeset a paragraph without bad boxes, and \emergencystretch is nonzero, it tries once again, but this time increasing the stretchability of the space by the value of this parameter.

  • Does it matter where you put this command? – tparker May 17 '18 at 14:07
  • 1
    I'd put in in the preamble, or within a group - depending on what you want to achieve. – mbork May 18 '18 at 11:16
28

another tactic, after fixing urls as described by Werner, is to wrap the environment \begin{sloppypar} ... \end{sloppypar} around just those paragraphs that still have problems.

this does much the same thing as setting \emergencystretch, with preset values.

  • 1
    \begin{sloppypar} uses \sloppy locally and is documented here: tex.stackexchange.com/a/50850/1340—that answer recommends considering emergencystretch over sloppy, as the former does not allow small overfull hboxes. – Blaisorblade Aug 27 '17 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.