2

I have a text (justified block paragraph) with an author attribution.

If the last line of the text has enough space left to fit the author attribution and some space, then it should be put into that line flushed right.

If the last line of the text doesn't have enough space, the author attribution should go to the next line flushed right, but the last line of the paragraph shouldn't be justified.

Foo bar foobar. Foo bar foobar. Foo bar foobar. Foo bar foobar. 
Foo bar foobar. Foo bar foobar. Foo bar foobar. Foo bar foobar. 
Foo bar foobar. Foo bar foobar. Foo bar foobar.   by the Author

Foo bar foobar. Foo bar foobar. Foo bar foobar. Foo bar foobar. 
Foo bar foobar. Foo bar foobar. Foo bar foobar. Foo bar foobar. 
Foo bar foobar. Foo bar foobar. Foo bar foobar.
                                              by another Author

How can I achieve this?

lockstep
  • 250,273
Toscho
  • 4,713
  • I think the amsthm proof environment uses similar logic to position the QED symbol at the end of a proof -- maybe look at its implementation? – John Wickerson May 09 '13 at 08:00

1 Answers1

4
\documentclass{minimal}

\def\signed#1{{\leavevmode\unskip\nobreak\hfil\penalty50\hskip2em
    \hbox{}\nobreak\hfil #1%
    \parfillskip=0pt \finalhyphendemerits=0 \endgraf}}

\begin{document}

Phasellus sagittis blandit tortor, vitae facilisis nisl molestie a. Proin
suscipit, purus in scelerisque bibendum, ligula magna hendrerit mauris, et
condimentum libero dui a tortor. ligula magna hendrerit mauris. \signed{A. Uthor}

\bigskip

Scelerisque bibendum, ligula magna hendrerit mauris, et
condimentum libero dui a tortor Phasellus. \signed{A. Uthor}

\end{document}

enter image description here