Can I somehow tell LaTeX to shrink the spaces in overfull hboxes rather than stretch them?

I have a paragraph full of very long words that mustn’t be hyphenated. Predictably, this produces an overfull \hbox warning: specifically Overfull \hbox (6.85588pt too wide). I can fix this with something like \setlength{\emergencystretch}{10em}, but in this case I end up with a line of three words and two hideously enormous spaces. Is there a way to set a length that that allows spaces to be shrunken instead of stretched, or otherwise squeezes the contents of the hbox when it’s a little bit overfull? Maybe a negative stretch? I’m basically hoping for something that does the opposite of the emergencystretch parameter.

Edit: It occurs to me that space shrinking would probably be fairly unhelpful in this case, as the resulting spaces would each end up less than half their original length, but I still want to know how to this.

  • 2
    Welcome to tex.sx. If you apply microtype (\usepackage{microtype}), that might help. (It will apply to the whole document.) – barbara beeton Nov 21 '19 at 1:17
  • can you not set the paragraph \raggedright ? – David Carlisle Nov 21 '19 at 1:20
  • @David I can definitely set the paragraph \raggedright, but then all of its lines look bad instead of just the one. – Gregory Gan Nov 21 '19 at 4:53
  • @GregoryGan you provided no example so it is had to say what looks bad but it is common advice to set large words in small columns ragged right rather than badly justified. If you have a paragraph where every word is 40% of linewidth no amount of stretching or shrinking space will get three words to a line so you have a choice of justifying and having a 20% gap in the middle, or setting ragged and having normal word spaces. – David Carlisle Nov 21 '19 at 7:51

There are several different levels of escalation when dealing with overfull boxes. Starting from the smallest impact on output quality:

  1. Add \usepackage{microtype}.

    This applies microtypographical enhancements to the document which can prevent overfull boxes and generally leads to fewer hyphenations.

  2. Rewrite the offending paragraph.

    It is often enough to add a filler word or replace a word with a synonym of different length or rearrange the subclauses to make overfull boxes go away.

  3. Play with TeX's linebreaking parameters.

    Linebreaking can be influenced by many parameters. First you could try to set \tolerance to a higher value (default 200), e.g. \tolerance=1000. This will allow lines with a badness of 1000.

    Another parameter is \emergencystretch (default 0pt). If spaces have to be stretched further than their regular stretchability, this parameter is added on top. Try for example \setlength{\emergencystretch}{1pt}.

    Sometimes the overfull hbox is super tiny, so it is not really visible by eye. You can silence the overfull hbox warning for those by tuning the \hfuzz parameter (default 0.1pt). This doesn't actually remove the overfull box but you won't be bothered about it anymore. Use with care!

    You want to restrict the action of all of the above values to the offending paragraph only. Therefore you should wrap the paragraph and the settings in a common group like so


    It is important that the paragraph break \par takes place within the group, otherwise TeX will perform the paragraph break outside the group and will have forgotten the parameters you set inside.

Now we're getting in the realm of “I don't care how it looks, just shut up”.

  1. Wrap the offending paragraph into \begin{sloppypar}...\end{sloppypar}.

    That will temporarily set the parameters I mentioned in (3.) to ridiculously high values, so that no overfull boxes should occur (unless you are in a strange situation where you have unhyphenatable material that is wider than the column).

  2. Add \sloppy after \begin{document}

    This does the same as \begin{sloppypar}...\end{sloppypar} but applies to the whole document. If for some reason you love the typical word processor type of justification, this setting is for you. If however you use LaTeX for its superior output quality, you should immediately forget that this even exists.

|improve this answer|||||
  • 1
    Thank you for the thorough response. While microtype is exactly what I wanted and more, I very much appreciate having a list of options. Even if I never let some of them see the light of day, they give me a much better idea of how to search for solutions to similar problems in the future. – Gregory Gan Nov 21 '19 at 4:57

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.