1

\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.

EDIT

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.

4
  • 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

1

You can try:

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

test:

\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.

0

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?

gives:

\special in xelatex

xelatex

MWE

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

\begin{document}
\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


\end{document}

or \pdfliteral in pdflatex

pdflatex

MWE

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

\begin{document}
\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


\end{document}

You must log in to answer this question.

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