[Tex/LaTex] How to draw horizontal line with rubber length

rules

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.

Best Answer

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}