18

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.

theobear
  • 837
  • 6
  • 17
  • I guess you can always play with break penalty... – Mario S. E. May 18 '13 at 14:13
  • 3
    Does this help? - http://tex.stackexchange.com/questions/28357/ensure-minimal-length-of-last-line/28361#28361 – topskip May 18 '13 at 14:15
  • We have reopened the question, now we would like to know if the linked question goes in the right direction :) – topskip May 18 '13 at 16:13
  • Thanks for your replys. that linked question might be useful... but I don't have any indent to the paragraphs. – theobear May 18 '13 at 17:59
  • 5
    A decidedly low-tech way would be to insert ties (~) manually between the penultimate and final words of a paragraph. – Mico May 18 '13 at 17:59
  • Neither @dıʞsdoʇ's nor @egreg's solution (in the linked to question) needs you use a non-zero \parindent. For egreg's solution, assign whatever value you wish to \mylength and replace \pardindent with \mylength. For the LuaTeX one, I'm pretty sure you can do something similar, though I'm not that familar with Lua, so.... – jon May 18 '13 at 21:53
  • 3
    Suppose you have a two line paragraph with only one word in the second line. It's quite improbable that another word can be accommodated in the second line without stretching too much spaces in the first line. Even adding ties would not help, because TeX might prefer hyphenation, if the alternative is worse, based on the current parameters. Only long enough paragraph allow for tricks like those outlined in the linked answers. Or a ragged right setting, of course. – egreg May 19 '13 at 22:03
  • 1
    I suppose I should have broken this into 2 questions, because the second example is really about centered text. The first example, in real life, would usually have more than one line of text. – theobear May 20 '13 at 13:46
  • I've decide to go the simple route as Mico suggested as the more complicated methods introduced other problems in my already complicated document. THANKS – theobear May 23 '13 at 01:07
  • 1
    The comments seem to be about adding extra words to the last line, you can also use \looseness=-1 to try and get the extra word onto the previous line. – StrongBad May 24 '13 at 17:48
  • You may also find this answer: http://tex.stackexchange.com/a/23924 useful. – jota Nov 19 '15 at 12:00

1 Answers1

13

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}
David Carlisle
  • 757,742
  • This doesn't seem to work with the parcolumns package... any idea of a work around? – theobear Jun 11 '13 at 23:10
  • @theobear paracol.sty ? – David Carlisle Jun 11 '13 at 23:37
  • http://www.ctan.org/pkg/parcolumns – theobear Jun 12 '13 at 01:11
  • I'm acutally using parcolumns and parcolsx (found here: http://tex.stackexchange.com/a/63997/26651) to do some side by side translations within the main text. your solution works for the main text but is ignored in the columns.... which is a pity as using the ~ tie seems to mess up the columns. – theobear Jun 14 '13 at 09:41