# [texhax] Custom justification (for captions)

Joel C. Salomon joelcsalomon at gmail.com
Tue May 18 19:31:44 CEST 2010

I’m trying to emulate a particular justification style.  (This is for
figure captions with the caption package.)

Specifics are:
Large left margin, flush to right margin, fully justified, EXCEPT---
if there’s only one line, it is to be right-justified.

Examples:

==================================================
Figure 2  ’Twas brillig & the slithy toves
did gyre and gimble in the wabe; all mimsy
were the borogoves.

==================================================
Figure 3 Short caption.

I have most of what I need with

\captionsetup{
margin={10em,0pt},oneside,
font=small,
labelfont=bf,labelsep=space}

except for the odd one-line justification rule.

I’m not sure how best to implement this.  Having read the caption
package docs, I think I’ll either need to write something like

\DeclareCaptionJustification{myoddjustification}{...}

--- but what goes in the {...}? --- or else a custom caption format like

\DeclareCaptionFormat{myoddformat}{...#1#2#3\par}

where the "..." is some sort of very stretchable glue.

What would be the best way to accomplish this?

--Joel Salomon