[Tex/LaTex] way to avoid short lines

line-breakingmemoirtypography

Is there a universal setting to tell TeX that the last line of a paragraph can not have just one word? For instance, instead of this:

This is a sample paragraph and there is one word
here.

you would have that:

This is a sample paragraph and there is
one word here.

Also, is there something comparable to InDesign's Balance Ragged Lines? Instead of this:

With centered text it would be better if more words were
on this line.

you would get that:

With centered text it would be better
if more words were on this line.

For information, I'm currently using LuaLaTex, the memoir class and the fontspec, microtype packages.

Best Answer

As long as your paragraphs are long enough to make it feasible you can limit the stretch of the \parfillskip that pads the final line. It is not so easy to specifically refer to a single word, but you can make it stretch at most (say) half the line). You may need to increase \emergencystretch or \tolerance to allow the rest of the paragraph enough flexibility to push the extra words on to the last line:

enter image description here

\documentclass{article}

\setlength\textwidth{6cm}

\def\a{One two three four five six. }
\def\b{\a\a\a\a}

\begin{document}

\b Bad.

Red yellow green. \b Blue black white bad.

\bigskip\hrule\bigskip

\setlength\parfillskip{0pt plus .4\textwidth}
\setlength\emergencystretch{.1\textwidth}


\b Bad.

Red yellow green. \b Blue black white bad.
\end{document}

Similarly if you make the glue used for centering have only finite stretch:

enter image description here

\documentclass{article}

\setlength\textwidth{9cm}

\def\a{One two three four five six. }
\def\b{\a\a\a\a}

\begin{document}

\begin{center}
With centered text it would be better if more words were
on this line. 
\end{center}

{\csname @flushglue\endcsname=0pt plus .25\textwidth
\begin{center}
With centered text it would be better if more words were
on this line. 
\end{center}}

\end{document}
Related Question