# How to draw horizontal line with rubber length?

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.

-

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

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

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

-

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.

-
Thanks, but I think xhfill seems easier. – Yun Huang Jul 26 '12 at 0:43
@YunHuang But xhfill only works in latex. – Andrew Swann Aug 3 '12 at 9:40