Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by egreg, Seamus, lockstep, mafp, Claudio Fiandrino May 9 '13 at 10:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
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 9 '13 at 8:00

1 Answer 1

up vote 4 down vote accepted
\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

share|improve this answer
    
You should cite the source. ;-) –  egreg May 9 '13 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 ;) –  Christian Lindig May 9 '13 at 10:18
1  
Yes, it's in the TeXbook. Look for Bourbaki in the index (or directly at page 106). –  egreg May 9 '13 at 10:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.