From: hank@ducvax.auburn.edu
Subject: Re: cantered last line
Organization: Auburn University, AL
Date: Thu, 1 Oct 1992 10:21:23 GMT

In article <8432681@MVB.SAIC.COM>, Miroslav Dont <DONT%CSEARN.BITNET@SHSU.edu> writes:
> How to center the last line of a paragraph?

Date: Fri, 28 Apr 89 12:02:39 EDT
From: Anne Brueggemann-Klein <abrueggemann@watdragon.waterloo.edu>
Subject: Re:  Obtaining a funny paragraph shape in TeX
Keywords: TeX, paragraph
 
In reply to:
 
>  From: Nico (Poppelier%Hutruu51.Bitnet@Cunyvm.Cuny.Edu)
>  Subject: Obtaining a funny paragraph shape in TeX
>  Keywords: TeX, paragraph
>
>  A matter of `house style' -- a few scientific journals published by a
>  publishing company in The Netherlands use a paragraph shape that I've
>  been trying to simulate in TeX, so far without success. Instead of
>  (underscores stand for white space):
>
>  aaaaaaaaaabbbbbbbbbbcccccccccc
>  ddddddddddeeeeeeeeeeffffffffff
>  gggggggggghhhhhhhh.___________
>
>  the paragraphs look like:
>
>  aaaaaaaaaabbbbbbbbbbcccccccccc
>  ddddddddddeeeeeeeeeeffffffffff
>  ______ggggggggghhhhhhhh.______
>
 
 
Have you ever wondered what negative stretch terms in glue are good for?
Here is how you can use them to center the last line of a paragraph.
 
   \leftskip=0pt plus 1fill
   \rightskip=0pt plus-1fill
   \parfillskip=0pt plus 2fill
 
All lines of a paragraph except the last one have \leftskip glue
at the left end and \rightskip glue at the right end. With the setting
above these two sum up to zero, passing the job of line stretching or
line shrinking to the normal interword spaces. The last line,
however, has \rightskip + \parfillskip = 0pt plus 1fill at the right end,
matched by \leftskip = 0pt plus 1fill at the left end. Hence, the last
line is centered, overriding stretch and shrink terms of normal interword
spaces.
 
Tinkering with TeX's parameters for line breaking is
real fun. Anyone with a real world application for negative
shrink terms?
 
Anne Brueggemann-Klein


%----------------------------------------------------------------------------
Date: Sun, 23 Apr 89 14:50:20 EDT
From: Steve_Tinney@um.cc.umich.edu
Subject: Re: parshape with last line centred
Keywords: TeX, paragraph
 
% Nico (Poppelier%Hutruu51.Bitnet@Cunyvm.Cuny.Edu) asks how to get
% the `funny paragraph shape':
%
%     aaaaaaaaaabbbbbbbbbbcccccccccc
%     ddddddddddeeeeeeeeeeffffffffff
%     ______ggggggggghhhhhhhh.______
%
% where underscores stand for whitespace. The following, which I
% simply adapted from the macros on p392 of the TeXbook, appears to do
% the trick (real users might want to alias the silly name!)
%-------------------------------------------------------------------
%
% strategy: 1) gather para into \vbox
%           2) break open vbox, and trim off last \hbox (= last line)
%           3) insert glue to compensate for \parfillskip
%           4) put back last line
%           5) insert the para for real
 
\def\parwithlastlinecentred#1\par{
    \setbox0=\vbox{\noindent#1\endgraf}% set para
    \setbox0=\vbox{%                     everything happens inside here
    \unvbox0 \setbox0=\lastbox %         move last line to box0
    \hskip0pt plus1fil %                 now compensate for the \parfillskip
    \unhcopy0 %                          put last line back
    }%                                   end of enclosing box0
    \box0\endgraf %                      do the insertion
}
 
% here's a demonstration...
 
\hsize=3in
 
\parwithlastlinecentred
aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm
nnn ooo ppp qqq rrr sss ttt uuu vvv www xxx yyy zzz
aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm
nnn ooo ppp qqq rrr sss ttt uuu vvv www xxx yyy zzz
aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm
nnn ooo ppp qqq rrr sss ttt uuu vvv www xxx yyy zzz
aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm
nnn ooo ppp qqq rrr sss ttt uuu vvv www xxx yyy zzz
 
\bye
 
Steve Tinney@um.cc.umich.edu



Subject: Re: Macro challenge
From: asnd@msr.triumf.ca (Donald Arseneau)
Date: 25 Mar 92 20:45:00 GMT

In article <ksv4tdINNg9p@utkcs2.cs.utk.edu>, eijkhout@cupid.cs.utk.edu 
(Victor Eijkhout) writes...
> In article <18726@ilog.fr>, skyvingt@ilog.fr (William Skyvington) writes:
> |> want is [...in a paragraph...] lines have roughly the same length:
> 
> This can be achieved by setting:
> \parfillskip=0pt \rightskip=0pt plus 1fil  
> in the paragraph that has to be broken with balanced lines.

This will give a raggedright paragraph with the last line much shorter
than the rest.  To get equally balanced lines, there must be substantial 
badness incurred when the glue is stretched.  Using very hard-to-stretch
glue will cause the spaces to get overly stretched.  I find 

\parfillskip=0pt \rightskip=0pt plus \hsize   

works well.

The reason for the counterintuitive result of  \rightskip=0pt plus 1fil  
is that all lines wind up with badness zero, so TeX fills each one up
as full as it can, then the last line gets the remainder.  This is exactly
the way most word proceessors arrange paragraphs.  You can use this TeXhnique
to get nicely shaped paragraphs, with the last line somewhat shorter than
the others, but avoiding great differences in size.  I wrote:

%
% Center a paragraph... like raggedcenter (TeXbook exercise 14.34).
% This is done in a group, but could be made to redefine \par to
% restore the changed parameters by brute force.  Note that the high stretch
% to lines actually REDUCES the number of nodes in the paragraph optimization
% from using .2\hsize.  It also favors a shorter last line because so many
% breakpoints have badness 0. (Any tolerance over 50?? will get all breakpoints)
% \rigidspacing isn't necessary for the appearance, but reduces the nodes.
% Unfortunately, \rigidspacing ignores font changes! so is left out.
%
\def\centerpar{\par \parindent\z@ \parfillskip\z@ %%% \rigidspacing
    \rightskip\z@ \@plus 3\hsize \leftskip\z@ \@plus 3\hsize
    \hyphenpenalty\@M \noindent}
%

Which gives very nice centered titles.

Donald