[Tex/LaTex] Smarter latex justification to avoid large spaces

horizontal alignment

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:

enter image description here

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

Best Answer

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 filled 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:

enter image description here

\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}

to your preamble. Without more information, it's difficult to assess how else to fix the problem.