[texhax] Positioning that depends on space available in the current line
Steve Schwartz
s.schwartz at imperial.ac.uk
Mon Jun 20 15:01:04 CEST 2011
Alex,
On Mon, 2011-06-20 at 13:14 +0100, Aleksandar Zec wrote:
> Hello,
>
> I would like to achieve this effect:
>
> aaaaaaaaaaaaaaaaaaaaaaaaa
> aaaaaaaaaaaaaaaaaaaaaaaaa
> aaaaaaa bbbbb
>
> aaaaaaaaaaaaaaaaaaaaaaaaa
> aaaaaaaaaaaaaaaaaaaaaaaaa
> aaaaaaa
> bbbbbbbbbbbbbbbbbbbbbb
>
> 'aaa' is a normal paragraph text. 'bbb' is a signature that should be
> positioned
>
> (1) on the right end of the last line if there is enough place;
> (2) in the next line if there is not enough place, right aligned.
>
> Any package/trick to do this automatically?
>
> Thank you in advance,
> Alex
Here's a macro I adapted from one I got from Phil Taylor via this group
some time ago. It is based on a macro to right-justify an end-of-proof
marker (a square) generalised to take an argument. I don't claim to
understand all the comments, but it works for me. [It doesn't work
inside display math mode for fairly obvious reasons, but I guess you
don't need that.] Looks similar to other fragments you've been sent.
Use as: aaaaa\pushright{bbbbb}
---------------------------------
\def\pushright#1{{% set up
\parfillskip=0pt % so \par doesnt push \square to left
\widowpenalty=10000 % so we dont break the page before
\square
\displaywidowpenalty=10000 % ditto
\finalhyphendemerits=0 % TeXbook exercise 14.32
%
% horizontal
\leavevmode % \nobreak means lines not pages
\unskip % remove previous space or glue
\nobreak % dont break lines
\hfil % ragged right if we spill over
\penalty50 % discouragement to do so
\hskip.2em % ensure some space
\null % anchor following \hfill
\hfill % push \square to right
{#1} % the end-of-proof mark (or whatever)
%
% vertical
\par}} % build paragraph
------------------
Steve
--
+-------------------------------------------------------------------+
Professor Steven J Schwartz Phone: +44-(0)20-7594-7660
Head, Space & Atmospheric Physics Fax: +44-(0)20-7594-7772
The Blackett Laboratory E-mail: s.schwartz at imperial.ac.uk
Imperial College London Office: Huxley 6M67A
London SW7 2AZ, U.K. Web: www.sp.ph.ic.ac.uk/~sjs
+-------------------------------------------------------------------+
More information about the texhax
mailing list