5

I want to have the last line in a paragraph be filled with an \hrulefill which sticks out 1cm to the right of the paragraph margin, like in this picture:

example paragraph

To typeset the above, I used \hangindent and \hangafter:

\hsize=9cm
\parindent=0pt
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\hrulefill\null
\hangindent=-1cm
\hangafter=-8

However I have to use the very sketchy \hangafter=-8 because I know that the example paragraph has 9 lines. Then if it has any other number of lines, it doesn't work. Is there something like \hangbefore=1, so that I don't have to tweak the number of lines every time? I'm lazy 😛

Also, I'd like to enforce that at least 1cm of rule shows up (or, put it another way, that no text appears in the 1cm that sticks out), so like in this case:

wrong output

I have instead mollit go to the next line, and the rest of the line be filled with the rule, like this:

correct output

(all of it without manual tweaking, of course).

7

Change \parfillskip

\hsize=9cm
\parindent=0pt

\def\righthang{{%
  \unskip
  \hangindent=-1cm
  \hangafter=0
  \parfillskip=\hangindent
  \hrulefill\null\par
}}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed 
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco 
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure 
dolor in reprehenderit in voluptate velit esse cillum dolore eu 
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non 
proident, sunt in culpa qui officia deserunt mollit anim id est 
laborum.\righthang

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed 
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco 
laboris nisi ut aliquip ex ea commodo consequat.\righthang

Duis aute irure dolor in reprehenderit in voluptate velit esse 
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat 
cupidatat non proident, sunt in culpa qui officia deserunt mollit 
anim id est laborum.\righthang

\bye

enter image description here

If you want that the last word does not go beyond the margin, you need a modified \hrulefill that is at least as long as the hanging indent.

\hsize=9cm
\parindent=0pt

\def\righthang{{%
  \unskip
  \hangindent=-1cm
  \hangafter=0
  \parfillskip=\hangindent
  \qhrulefill\null\par
}}
\def\qhrulefill{\leaders\hrule\hskip 1cm plus 1fill}


Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed 
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco 
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure 
dolor in reprehenderit in voluptate velit esse cillum dolore eu 
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non 
proident, sunt in culpa qui officia deserunt mollit anim id est 
laborum.\righthang

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed 
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco 
laboris nisi ut aliquip ex ea commodo consequat.\righthang

Duis aute irure dolor in reprehenderit in voluptate velit esse 
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat 
cupidatat non proident, sunt in culpa qui officia deserunt mollit 
anim id est laborum.\righthang

\bye

enter image description here

| improve this answer | |
  • Awesome! Thanks a lot 😉 – LaTeXer Mar 15 at 20:51
  • A quick question: why does the last paragraph in your screenshot seems to have a bit less than 1cm worth of \hrulefill if the \rightskip enforces (or so I think) at least 1cm of space there? Not that it matters much (if I add an a more, the line breaks), but it got me thinking... – LaTeXer Mar 15 at 21:37
  • @LaTeXer Added the new version – egreg Mar 15 at 21:59
  • 'kay, I think I got it. Thanks again! – LaTeXer Mar 15 at 23:09
8

Using \hangindent and \hangafter seems unnecessarily complicated here, I think you can simply make the rule stick out by 1cm:

enter image description here

\hsize=9cm
\parindent=0pt

\def\righthang{%
  \unskip
  \hrulefill\kern-1cm\relax
}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed 
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco 
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure 
dolor in reprehenderit in voluptate velit esse cillum dolore eu 
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non 
proident, sunt in culpa qui officia deserunt mollit anim id est 
laborum.\righthang

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed 
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco 
laboris nisi ut aliquip ex ea commodo consequat.\righthang

Duis aute irure dolor in reprehenderit in voluptate velit esse 
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat 
cupidatat non proident, sunt in culpa qui officia deserunt mollit 
anim id est laborum.\righthang

\bye
| improve this answer | |
  • or set hsize to 8cm if you want the 9cm to include the extra rule width – David Carlisle Mar 15 at 23:45
  • Yeah, much simpler indeed. Thanks! – LaTeXer Mar 16 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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