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?

1
  • 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? Commented May 9, 2013 at 8:00

1 Answer 1

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

3
  • You should cite the source. ;-)
    – egreg
    Commented May 9, 2013 at 9:47
  • You are right, this is not code that I wrote but found in same package and then used in my own documents. Shame on me, I don't remember which package it was. But I guess you know ;) Commented May 9, 2013 at 10:18
  • 1
    Yes, it's in the TeXbook. Look for Bourbaki in the index (or directly at page 106).
    – egreg
    Commented May 9, 2013 at 10:31

Not the answer you're looking for? Browse other questions tagged .