Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a line that happens to end in a non-breakable code-fragment

This is a long line that ends in a \pre{std::ostream}
long word.

When printed the line is too full. The spaces between the words on the line are as slim as they can be.

I would like to relax the spacing rules for that line so that the spaces will be stretched as needed to bring the pre-word on the next line, even if that space stretch will not look very nice anymore

This   is   a   long   line   that   ends   in   a
\pre{std::ostream} long word.

I did put \hfill between all those words, but that can not be the solution, right?

Update: It seems to make a difference that the problematic line is inside a list item. Is there a "paragraph-less" solution that works on both, paragraphs and list items (and supposedly in many other cases)?

* This is a long line that ends in a \pre{std::ostream}
  long word.


* This   is   a   long   line   that   ends   in   a
  \pre{std::ostream} long word.

When I use sloppypar I get an additional line break.

enter image description here

share|improve this question
Issue \linebreak before \pre{std::ostream} would also do the trick. See Underscore makes text go past end of line into margins. –  Werner Sep 3 at 20:05
Can't you just re-word the text? Ad an adjective on an appropriate place, or sort-of a filler word? Or remove a word? That would help, too. –  tohecz Sep 4 at 7:52
@tohecz Only as a last resort. a) I want to know a solution for the future, b) it is not big a overfull box that that last resort is needed I thought c) I am past orthography proof reading and do not want to introduce any new ones ;-) –  towi Sep 4 at 7:59
@towi (as a math journal typesetter) Sometimes I modify the text to get rid of bad line just before the proofs (i.e., before sending the article to the authors for a final check). However, I only do small stuff like adding or removing "that" in appropriate places etc. I think you could re-consider the work-flow and allow such occasional minor changes. But you ought to know what's better, I only shoot some ideas ;) –  tohecz Sep 4 at 8:02
@tohecz You are correct, of course. Like "vom Typ" to "von dem Typ" -- identical meaning, better linebreak. +1 –  towi Sep 4 at 9:10

2 Answers 2

up vote 7 down vote accepted

Whereas \sloppy will loosen the alignment constraints on the whole document, the sloppypar environment can limit the effect of the damage to a localized area.

In my MWE, the \hrulefill shows the extent of the left/right margins.


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxThis is a long line that ends in a 
  \pre{std::ostream}long word.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxThis is a long line that ends in a 
  \pre{std::ostream}long word.

enter image description here

It helps to understand that when TeX (which underlies LaTeX) is justifying a paragraph, it attempts to satisfy a set of weighted constraints and penalties to guide the layout. When the constraints posed by these penalties cannot be met, an overfull or underfull box results, which looks to the user as a margin over- or underrun. This is what is happening when a line is ending in a long unbreakable object (I used a box in my MWE).

By using the sloppy settings, the weights and penalties are revised to make "a" solution more likely. As you point out, the sloppy solution may be more ugly in some ways, but it will largely eliminate the margin overruns that can otherwise result.

share|improve this answer
Alas, my problematic line is inside a list-item. When I use sloppypar inside that I get an extra line break (but with sloppy white spacing at least). Sorry, did not know that that was important. I updated the question –  towi Sep 4 at 7:22
I found the solution it seems. \sloppy and \fussy in the beginning of the respective paragraphs/items. –  towi Sep 4 at 7:33
@towi Or \item {\sloppy My bad very bad paragraph.\par} –  tohecz Sep 4 at 8:08
@tohecz I think I tried that but it didn't work. I might be mistaken. –  towi Sep 4 at 9:09
"It helps to understand that when LaTeX is justifying a paragraph..." -> "It helps to understand that when TeX is justifying a paragraph...". LaTeX is only macro package which doesn't justify paragraph and doesn't calculate with penalties, demerits, badness etc. in the way described above. This is work for TeX. –  wipet Sep 4 at 9:23

To summarize the answer from @steven-b-segletes and @werner I want to share my results with everyone.

Here is what the different solutions look like:

enter image description here

At the end of each paragraph I noted what that paragraph was set with:

  • original
  • \linebreak
  • \begin{sloppypar}
  • \sloppy and \fussy
  • back to original
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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