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 want to overline a piece of text, but the line is too close to the number, which is not nice, so I want to add some kind of padding between the overline and the text. This is what I've made up so far:

$\overline{\mbox{XXX\raisebox{0.8cm}{}}}$

where XXX is the text I want to overline.

This looks very ugly for me, so I was wondering whether there is any better way to do it.

share|improve this question
1  
probably \overline{\strut XXX} (or make a similar different strut if that isn't the correct spacing, but strut is used in other places to get even vertical spaces) –  David Carlisle Dec 19 '12 at 11:12
add comment

2 Answers

up vote 4 down vote accepted

The following example shows some alternatives.
Remarks:

  • \raisebox can also be used to specify the final height (and depth). The height is known as \height that can be used for calculations (\dimexpr or package calc).

  • \vphantom: placeholder for height and depth of the argument. The argument is not set and the width is zero.

  • \rule with zero width can be used to insert an invisible vertical rule.

  • \strut adds a invisible vertical box with height .7\baselineskip and depth .3\baselineskip.

Example file:

\documentclass{article}

\makeatletter
\newcommand*{\ov}[1]{%
  $\m@th\overline{\mbox{#1}}$%
}
\newcommand*{\ovA}[1]{%
  $\m@th\overline{\mbox{#1}\raisebox{3mm}{}}$%
}
\newcommand*{\ovB}[1]{%
  $\m@th\overline{\mbox{#1\rule{0pt}{3mm}}}$%
}
\newcommand*{\ovC}[1]{%
  $\m@th\overline{\mbox{#1\strut}}$%
}
\newcommand*{\ovD}[1]{%
  $\m@th\overline{\mbox{#1\vphantom{\"A}}}$%
}
\newcommand*{\ovE}[1]{%
  $\m@th\overline{\raisebox{0pt}[1.2\height]{#1}}$%
}
\newcommand*{\ovF}[1]{%
  $\m@th\overline{\raisebox{0pt}[\dimexpr\height+1mm\relax]{#1}}$%
  % Package `calc' can be used as alternative for `\dimexpr'.
}
\newcommand*{\ovG}[1]{%
  $\m@th\overline{\raisebox{0pt}[\dimexpr\height+1mm\relax]{#1\vphantom{A}}}$%
}
\makeatother

\begin{document}

\setlength{\parskip}{5mm}

\ov{XXX} \ov{xxx} \ov{\"A}

\ovA{XXX} \ovA{xxx} \ov{\"A} \qquad\verb|\raisebox{3mm}{}|

\ovB{XXX} \ovB{xxx} \ov{\"A} \qquad\verb|\rule{0pt}{3mm}{}|

\ovC{XXX} \ovC{xxx} \ov{\"A} \qquad\verb|\strut|

\ovD{XXX} \ovD{xxx} \ov{\"A} \qquad\verb|\vphantom{\"A}|

\ovE{XXX} \ovE{xxx} \ov{\"A} \qquad\verb|\raisebox{0pt}{1.2\height}|

\ovF{XXX} \ovF{xxx} \ov{\"A} \qquad\verb|\raisebox{0pt}{\height+1mm}|

\ovG{XXX} \ovG{xxx} \ov{\"A} \qquad\verb|\raisebox{0pt}{\height+1mm} + \vphantom{A}|

\end{document}

Result

share|improve this answer
    
Very nice list, for all kind of different needs. I actually went the \strut way, but the \vphantom method looks very nice for longer texts –  SztupY Dec 19 '12 at 18:07
add comment

The separation is controlled by a font parameter, so it's a bit difficult to change it. You can add a predetermined height to the text:

\documentclass{article}

\newcommand{\tolstrut}{%
  \vrule height\dimexpr\fontcharht\font`\A+.1ex\relax width 0pt\relax
}

\DeclareRobustCommand{\textoverline}[1]{%
  \ensuremath{\overline{\mbox{\tolstrut#1}}}%
}

\begin{document}
\textoverline{no} \textoverline{with}
\end{document}

Play with the 0.1ex dimension, trying various values until you're satisfied.

enter image description here

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.