[texhax] forcing a piece of text to the right margin, even on a blank line

Lars Madsen daleif at imf.au.dk
Sun Dec 30 19:18:33 CET 2007


Steve Schwartz :

> Dear All,
>
> I have one that has defeated me, but should be solvable. Our exam style
> puts the marks for a particular question on the last line of that
> question, but pushed to the right edge (with a bit of leading space) if
> there's room. Else it goes on the next line all by itself, but still
> aligned along the right margin, i.e.,
>
> |blah blah      [2 marks]|
>
> and
>
> |blah blah blah blah blah|
> |               [2 marks]|
>
> where | shows the edge of the text. Try as I might, I can't generate a
> macro that will do this. It's easy to do the first, but if the line is
> too long, leading space tends to get gobbled up and I end up with:
>
> |blah blah blah blah blah|
> |[2 marks]               |
>
> I've tried all manner of boxes, \phantoms, etc. The best I have managed
> is:
>
> \newcommand\qmarks[1]{\quad\nolinebreak\hfill{[#1~qmarks]}}
>
> which needs to be placed immediately after the question without any
> space, i.e.,
>
> blah blah blah blah blah\qmarks{2}
>
> This ALWAYS gets the marks to the right edge, because it drags the last
> blah to the next line with it. This makes for ugly lines as tex
> desperately stretches the rest out. I attach a short sample for someone
> to play with.
>
> With best wishes for the New Year,
> Steve
>

This is a well known problem from whenever preople want to create their 
own proof environments, it always goes wrong.

But there is a solution, use the following construction stolen from 
amsthm.sty:

\leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
     \quad\hbox{blah}

(the text part of the definition of \qed), I've stolen this many times, 
and it works just fine



/daleif


More information about the texhax mailing list