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.

If I want to draw an overline over some text, not an equation, how can I do it? \overline seems to only work in math mode, and when used outside of math mode, it automatically says "Missing $ inserted".

share|improve this question
add comment

4 Answers

up vote 10 down vote accepted

Easy answer:

\newcommand{\textoverline}[1]{$\overline{\mbox{#1}}$}

Not so easy, but neater:

\makeatletter
\newcommand*{\textoverline}[1]{$\overline{\hbox{#1}}\m@th$}
\makeatother

We use the normal \overline of math mode, exploiting the fact that a \hbox in math mode typesets its argument in the font which was current at the time the math formula starts (also keeping spaces).

The strange \m@th is a precaution against possible setting of the parameter \mathsurround, a space added before and after in-line math formulas; it's usually zero, but a class might change it. When math mode is used for things like this, it's best to be on the safe side: \m@th sets the parameter to zero, but since a math formula forms a group, the setting is local and won't change the global one.

share|improve this answer
2  
IMHO it should be called \textoverline, just to be consistent with all the other \text... macros. –  Martin Scharrer Jul 26 '11 at 14:01
3  
@Martin Done. The definition is just copied from the kernel (re)definition of \underline. –  egreg Jul 26 '11 at 14:04
add comment

If you want to have line breaks in the text you can use the soul package:

\documentclass{article}
\usepackage{soul}

\newcommand\ol[1]{{\setul{-0.9em}{}\ul{#1}}}

\begin{document}
\ol{This is under a line.}

\Huge\ol{This is under a line.}
\end{document}

The disadvantage of this approach is that the line height does not depend on the height of the content (so capital letters with accents will be problematic). It does scale with font size though.

share|improve this answer
add comment

The basic answer to your question is that you can use the \overline{} command from math mode for text, too, if you combine it with \mbox{} command. The \mbox{} command lets you shift out of math mode while being in math mode. So try this:

\documentclass{article}
\begin{document}
$\overline{\mbox{This is under a line}}$ but this isn't.
\end{document}

Your question was essentially answered by egreg but there wasn't much explanation and this is a little too long to put as a comment.

share|improve this answer
add comment
\documentclass{article}
\newsavebox\TBox
\def\textoverline#1{\savebox\TBox{#1}%
  \makebox[0pt][l]{#1}\rule[1.1\ht\TBox]{\wd\TBox}{0.4pt}}
\begin{document}

\textoverline{foo}
\textoverline{\textit{foo\"A}}
\tiny\textoverline{bar}

\end{document}
share|improve this answer
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.