15

The \hrulefill command could draw rubber length underlines, like abc___def. I just want to draw line in the vertical centre of a text, like abc---def. Thanks.

2 Answers 2

12

The xhfill package provides different leader commands to do exactly this:

enter image description here

\documentclass{article}
\usepackage{xhfill}% http://ctan.org/pkg/xhfill
\setlength{\parindent}{0pt}% Just for this example
\begin{document}
abc\xrfill{1pt}xyz \par
abc\xrfill[.5ex]{.4pt}xyz
\end{document}

Specifically regarding your question, \xrfill[<raise>]{<width>} prints a rule of width <width> raised <raise> from the baseline. Other leader options are also provided by the package. See the documentation for more examples.

For drawing a rule of specific (rather than rubber) length, you can always use a regular raised \rule:

enter image description here

\documentclass{article}
\setlength{\parindent}{0pt}% Just for this example
\begin{document}
abc\hspace{4cm}xyz \par
abc\raisebox{.5ex}{\rule{4cm}{.4pt}}xyz
\end{document}
3

The command \leaders is intended for such things. In your case you can write

abc\leaders\hrule depth -2pt height 2.4pt\hskip 10pt plus 1fill xyz

to get a rule of height 0.4pt raised 2pt above the baseline with minimum width 10pt.

2
  • Thanks, but I think xhfill seems easier.
    – Yun Huang
    Jul 26, 2012 at 0:43
  • @YunHuang But xhfill only works in latex. Aug 3, 2012 at 9:40

You must log in to answer this question.

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