6

I would insert two horizontal line here an example:

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

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

Mazzy
  • 7,642
  • 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 09 '12 at 20:52

2 Answers2

8

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}}
David Carlisle
  • 757,742
Werner
  • 603,163
1

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}
henrique
  • 6,616