Friday, January 7, 2011

Center last line in a paragraph

I'm not totally sure why one would want to center the last line in a paragraph, but the excellent TeX by Topic provides a surprising solution.
\leftskip=0pt plus.5fil
\rightskip=0pt plus-.5fil
\parfillskip=0pt plus1fil
The reason this works is that for all lines except for the last, the amount of stretch in the line is 0, so no skips are inserted. In the last line, the addition of the \parfillskip gives a skip of .5fil on the left and right so the line is centered.

4 comments:

  1. Well, things like that can be seen on the back of some books, lecture posters etc. Plus, it's yet another example of something TeX can do and Word can't;). And a nice trick with TeX's line-breaking stuff.

    ReplyDelete
  2. It is neat. I don't think I've ever seen it used before though.

    ReplyDelete
  3. It is used by caption and ccaption packages to center the last line of the captions

    ReplyDelete