\hrulefill vertically aligns the line at the bottom of the text. There is also \xrfill in the package xhfill which raises the line, but it is raised too much for my esthetics.

What I'm looking for is a command working similarly to \hrulefill, but such that the filler line is like a stretched em-dash, so the vertical alignment is the same as for an em-dash.


As a clarification: I don't want to have to guess the thickness nor the amount the line is raised over the baseline. I want a command which produces a stretched em-dashed, independently of the current font size etc.

  • See: tex.stackexchange.com/questions/282342/… In xelatex, I tried this \documentclass{article}\begin{document} x \special{pdf:literal 1 0 0 1 0 2 cm} \hrulefill \special{pdf:literal 1 0 0 1 0 -2 cm} x x -- x\end{document}
    – Cicada
    Commented May 17, 2020 at 14:35
  • @Cicada Thank you. This looks like a pretty technical approach to me. I'm not using xelatex. Shouldn't there be a smoother way to accomplish this in pdflatex?
    – azimut
    Commented May 18, 2020 at 11:56
  • pdftex uses \pdfliteral, per the linked question. You can define a macro to do the technical bit and just call the macro (use a short name to save typing). Or do you want to do it some other way? Draw a \rule and use \raisebox, for example.
    – Cicada
    Commented May 18, 2020 at 12:17
  • @Cicada thank you. Would you mind making a regular answer out of your ideas?
    – azimut
    Commented May 20, 2020 at 6:37

2 Answers 2


You can try:

\def\myrulefill{\leaders \hrule height\myrulefillat 
                                depth-\dimexpr \myrulefillat-.3pt\relax \hfil}


\hbox to3cm{a --\myrulefill -- b}

The height of this rule is given by \myrulefillat macro and the thickness is .3pt. You can set another values.


Since the rule is drawn in relation to the baseline, raising the baseline will raise the rule.

And since the command syntax is long and very low-level, storing all the technicality in a macro with a short name is useful and saves typing.

Using this answer (David Carlisle + a comment by flow), raising the baseline without using boxes or lua, Possible to vertically shift baseline without using a box?


\special in xelatex



\newcommand\hrf{\special{pdf:literal 1 0 0 1 0 2 cm}\hrulefill\special{pdf:literal 1 0 0 1 0 -2 cm}}

\textbackslash special with xelatex

no change x\hrulefill x

raised x\special{pdf:literal 1 0 0 1 0 2 cm}\hrulefill \special{pdf:literal 1 0 0 1 0 -2 cm}x

macro x\hrf x


or \pdfliteral in pdflatex



\newcommand\hrfp{\pdfliteral{ 1 0  0 1 0 2 cm}\hrulefill\pdfliteral{ 1 0  0 1 0 -2 cm}}

\textbackslash pdfliteral with pdflatex

no change x\hrulefill x

raised x\pdfliteral{ 1 0  0 1 0 2 cm}\hrulefill\pdfliteral{ 1 0  0 1 0 -2 cm}x

macro x\hrfp x


You must log in to answer this question.

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