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.

I would insert two horizontal line here an example:

  -------
    Foo
  -------

I had used hrulefill but the line has the length of the page.

share|improve this question
1  
Why the "unaccept" of my answer? Is there anything different that you want with respect to your question? –  Werner Oct 28 '12 at 16:05
    
Yes unfortunately it doesn't satisfy me infact I haven't the same space up and down of my text but I get two different spaces –  Mazzy Oct 28 '12 at 20:14
1  
The \overline/\underline approach should work though, right? Or are you concerned with the descenders/ascenders causing problems with the depth/height of your output? You could update the question to reflect your concerns, perhaps providing more attention to the subject and getting better answers. –  Werner Nov 9 '12 at 20:52

2 Answers 2

You could use

\begin{tabular}{c}
  \hline
  Foo \\
  \hline
\end{tabular}

This should leave an overlap of the horizontal rules of length \tabcolsep on either side of Foo. Other, perhaps more crude ways of obtaining this kind of output include

$\overline{\mbox{\underline{\ Foo\ }}}$

Of course, regardless of the choice, if this is a frequent use of something, consider making a macro:

\newcommand{\ouline}[1]{%
  \begin{tabular}{c}
    \hline
    #1 \\
    \hline
  \end{tabular}}
share|improve this answer

You can create a length for your bar and then set its width to the same width of a text, something like:

\newlength{\foorulewidth}
\settowidth{\foorulewidth}{Foo}

Later you can create a command to do the whole thing. Something like:

\makeatletter
\newcommand{\ruledtext}[1]{
    \newlength{\ruledtextwidth}
    \settowidth{\ruledtextwidth}{#1}
  \rule[.2\baselineskip]{\ruledtextwidth}{.3pt}\par
  #1\par
  \rule[.2\baselineskip]{\ruledtextwidth}{.3pt}
  \let\ruledtextwidth\@undefined  % This is needed to be able to use the same length later
  }
\makeatother

Here's a MWE:

\documentclass[12pt]{article}
\makeatletter
\newcommand{\ruledtext}[1]{
    \newlength{\ruledtextwidth}
    \settowidth{\ruledtextwidth}{#1}
  \rule[.2\baselineskip]{\ruledtextwidth}{.3pt}\par
  #1\par
  \rule[.2\baselineskip]{\ruledtextwidth}{.3pt}
  \let\ruledtextwidth\@undefined  % This is needed to be able to use the same length later
  }
\makeatother

\begin{document}

\ruledtext{Foo}

\ruledtext{Bar}

\ruledtext{create a horizonal line having the length of the text}

\end{document}
share|improve this answer

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.