TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to have a horizontal line extending from the end of the text on a line to the right margin. So far I've found \hrulefill and \leaders\hrule\hfill, but these draw a line that's flush with the baseline of my text — how can I get it to be vertically centered?

share|improve this question
up vote 7 down vote accepted
Here is some text\xfill{1pt} \par
Here is some text\xfill{8pt} \par
Here is some text\xhrulefill{blue}{2pt}\par
Here is some text\xhrulefill{cyan}{1ex}\par
Here is some text\xrfill[0ex]{1ex}[red] \par

enter image description here

share|improve this answer
Is the command \xfill defined in hxfill? It seems not. – egreg Oct 24 '11 at 21:51

You can define a command similar to \hrulefill, but changing the height and depth of the rule used:


\def\Vhrulefill{\leavevmode\leaders\hrule height 0.7ex depth \dimexpr0.4pt-0.7ex\hfill\kern0pt}


\noindent text\hrulefill

\noindent text\Vhrulefill


enter image description here

share|improve this answer

  \leaders\hrule height.5ex depth\dimexpr-.5ex+0.4pt\hfill\hbox{}%



A paragraph outside the environment can be ended with the
command \verb|\filltoend| like this one.\filltoend

In this environment all paragraphs will be ended with a line.

As it's shown here.

enter image description here

The advantage of this approach with respect to the other proposed solutions is that it has no issues when the paragraph happens to end exactly at the right margin. However it won't work, for TeXnical reasons, with list environments inside filllines (list environments redefine \par in terms of the primitive commands, not taking into account its present meaning), but \filltoend will work.

If a rule is needed no matter what, change the specification

  \leaders\hrule height.5ex depth\dimexpr-.5ex+0.4pt\hfill


  \leaders\hrule height.5ex depth\dimexpr-.5ex+0.4pt\hskip1em plus 1fill

which will draw a rule at least 1em wide.

share|improve this answer

The following \centerline[<height>][<thickness>] produces a rule at height <height> (default is 0.5ex) and thickness <thickness> (default is 0.4pt). The horizontal alignment is not entirely optimal compared to a traditional \hrulefill, but this is perhaps not an issue.

enter image description here

\usepackage{linegoal}% http://ctan.org/pkg/linegoal
\usepackage{xparse}% http://ctan.org/pkg/xparse
\NewDocumentCommand{\centerrule}{O{0.5ex} O{0.4pt}}{%
Here is some text\centerrule \par
Here is some text\centerrule[0pt] \par
Here is some text\centerrule[0.5ex][1pt] \par
Here is some text\centerrule[0pt][2pt]

The interface is provided by the xparse package, while the end-of-line estimation is done using \linegoal (from the linegoal package). It requires at least 2 compiles.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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