I would like to underline a whole line with a single word in the beginning of the line. I tried


but this underlines only the word ``HOMEWORK'', leaving the rest of line not underlined.

Any other suggestion?


3 Answers 3


It might be easiest to create a macro to do this which measures the length of the text and then produces an \hspace for the remaining space:




  • Thanks! this looks good but an anomaly occurs: for some reason the underline is one character longer then the width of the page. Can you figure how to cure this?
    – user1999
    May 21, 2011 at 21:35
  • It's not for me. Are you using this exact document? (Try adding \usepackage[showframe]{geometry} and this will show you that the line is the same length as the textwidth.)
    – Alan Munn
    May 21, 2011 at 21:48

This is an old question but the answers proved unsatisfactory for me and I spent countless hours tearing my hair out. What I ended up arriving at was \uline from the ulem package. This allows the inclusion of a \hfill to stretch the line to the end of the page, which allows the underline to start from somewhere other than the left edge.



The \hspace is just there to show it doesn't have to start at the left margin.


The macro \hrulefill tells TeX to fill with a rule the available space, but in your case there's none: \underline{...} creates a box as wide as the text inside.

What you probably want is "HOMEWORK" on a line by itself followed by a horizontal rule across the whole page. Then


should do what you need.

If you think that the spacing is excessive, don't. :) Underlining is frowned upon in typography. However, you can play with spacing by trying

\par\hbox{\scshape homework}\kern1pt\hrule\kern3pt

giving different values until you're satisfied.

  • Thank you for your suggestion! This gives the underline the correct length, but it puts it too much beneath the word. The solution of Alan seems to be more appropriate from the aesthetical aspect.
    – user1999
    May 21, 2011 at 21:30
  • @user1999: see edited message
    – egreg
    May 21, 2011 at 21:45
  • You could raise the line if you like by adding a \vspace{-2pt} before the \hrule.
    – Alan Munn
    May 21, 2011 at 21:49
  • @egreg Is there any substantive difference between adding \vspace and using \kern?
    – Alan Munn
    May 21, 2011 at 21:51
  • @Alan: TeX doesn't break pages at kerns, if they are not immediately followed by glue. So with the (edited) code, there won't be a legal breakpoint between the header, the rule and the text following them, since TeX doesn't add interline glue before and after horizontal rules. The "excess" space in the original code is produced by the \strut in the \hbox.
    – egreg
    May 21, 2011 at 22:11

You must log in to answer this question.

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