Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

up vote 13 down vote accepted

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}
share|improve this answer
add comment

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.