Possible Duplicate:
Is there a way to measure the remaining space of a line of text?

I have some text and want to put a \hrulefill at the end following by a period. However, if the text of the line comes too close to the end of the line, the rule is omitted and just a period results -- or -- a new line is created, the rule is omitted, and the line begins with a period.

How can I determine if there is enough space at the end of the line for a sizeable enough hrulefill of some specified length?

  • As @Ben said this is actually a duplicate in the general case. However, if Phil's answer does it for you as well I would accept it and the question could stay, under a different, more specific title. – Martin Scharrer Sep 15 '11 at 6:28

How about the following (using ideas from the command \qed in amsart.cls):

\newcommand{\myrulefill}{\unskip\penalty9999 \hbox{}\nobreak\hrulefill
  \hbox to 1em{\hrulefill}.}

That guarantees you at least 1em of hrulefill (you can change that 1em to some other length, of course), and prevents the hrulefill from being on a line by itself. You'd just put the command \myrulefill at the end of your paragraph.

  • I implemented this and it works like a charm! Thanks for everyone's help. Sorry for the duplicate. – Doug Sep 15 '11 at 21:10
  • @Doug: No problem. This is a specific case and therefore not an exact duplicate. Please accept this answer then by clicking the tick mark on the top left of it. Thanks. – Martin Scharrer Sep 16 '11 at 7:04

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