This question is closely related to How can I right-align a quotation attribution, on the same line as the quotation if possible?

I am currently using the TeXBook's excellent solution, among those described in that question, except for a minor change in spacing (a 1em gap between the quotation and the attribution instead of 2em):

    \parfillskip=0pt \finalhyphendemerits=0 \par}}

However, an additional problem has arisen: I am setting this text in two columns, and some attributions end up breaking onto multiple lines. This tends to look silly right-aligned:

image of situation described above, with attribution starting partway through a line

In general, I would much rather have the attribution begin left-aligned on a new line, should it require more than one line:

enter image description here

I need an automated solution because I'm generating the text programmatically. I will be doing some manual tweaking afterwards, but as I'm typesetting over 10,000 of these entries, anything that can be done to get most of them right automatically is a huge time-saver.

  • It would be possible to typeset the quote in a box, measure the width of the last line, then measure the attribution and decide what's the thing to do.
    – egreg
    Apr 29, 2018 at 22:00

1 Answer 1


Here's my shot at it, using etoolbox and calc:



    \parfillskip=0pt \finalhyphendemerits=0 \par}}

We set \attrlength to the width of the argument (which is the text we want to set as the attribution), then if it's less than the width of a column we use the TeXBook's macro described in the question; otherwise we start a new paragraph and set the text there.

The final macro, \longattrnobreak, is used in cases where the entry looks better when the attribution starts on the same line as the quote but is left-aligned thereafter:

enter image description here

enter image description here

I can't think of a clean, easy-to-implement heuristic for this (from my five minutes thinking about it, it involves both the width of the last line of the quotation and the width of the last line of the attribution, plus how that line's width compares to the one above it), so I'll choose this one manually at proof time if the automatic choice of the first two options looks bad.

You must log in to answer this question.

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