# Smarter latex justification to avoid large spaces

The default format in latex for paragraphs is fully justified, where the first word of a line touches the left margin and the last word of a line is flush with the right margin.

This is nice for lines that are about as long as the width of the text area, but if there are few words, LaTeX will create large amounts of whitespace between the words so they touch both sides.

In a document editor like Word or Writer, when I set the format to fully justified, this only applies to lines within a certain range of the edge as in almost every line is fully justified unless a line is specifically shorter and in that case appears left justified.

Here's an example image comparing the two:

Is there a way to do the equivalent justification in LaTeX?

• The default output from LaTeX is justified, but not in the way you show it. It would be really helpful if you could provide a minimal working example (MWE) that reproduces the LaTeX output you provide. This should start with \documentclass{...} and end with \end{document}.
– Werner
Nov 28, 2012 at 3:12
• This is not the default format in latex for paragraphs! Could you tell where you got that information? If it's from some online resource, it might be worthwile to try to get that changed. Nov 29, 2012 at 13:46
• Unfortunately, in any kind of typesetting scenario, any time, any where, TeX wins over Word, LibreOffice, Open Office etc. all combined. I say unfortunately because it would be a good pressure on the TeX side to take the competition seriously if any of these tools could implement TeX like optimization schemes. Right now, it's a matter of second place among those tools. Having said that, you are without a doubt, modifying some settings or a package is modifying erroneously. It's a typical MS Word artifact when you justify the paragraphs but no way in TeX. Nov 29, 2012 at 13:53
• Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question.
– Werner
Nov 29, 2012 at 15:08

You are most likely loading a package or manually setting the value of \parfillskip. The definition of \parfillskip, from TeX for the Impatient (section on Shaping paragraphs, p 111):

This parameter specifies the horizontal glue that TEX inserts at the end of a paragraph. The default value of \parfillskip is 0pt plus 1fil, which causes the last line of a paragraph to be ﬁlled out with blank space. A value of 0pt forces TEX to end the last line of a paragraph at the right margin.

As an example, this is the effect:

\documentclass{article}
\newcommand{\fourscore}{\noindent Four score and seven years ago our fathers
brought forth on this continent a new nation, conceived in liberty,
and dedicated to the proposition that all men are created equal.\par}
\begin{document}
\fourscore
\setlength{\parfillskip}{0pt}
\fourscore
\end{document}


So, restoring it can either be done by finding the "offending" package, or adding

\setlength{\parfillskip}{0pt plus 1fil}


• TeX will scream about Underfull \hbox, right? Nov 28, 2012 at 7:50
I used latex for my thesis and when I ended a paragraph, I used \linebreak command but it was a huge mistake that took hours to figure out. If you are using \justify command to fully justify your text in your document, then use \\ to end your paragraphs not \linebreak. With just this small change, all your unwanted spaces are removed.
• Welcome to TeX.SX! Paragraphs should not end with \\, but by leaving an empty line after them. Jul 12, 2014 at 10:31