5

I stumbled over a problem, which I assume should be quite common, but I couldn't find a satisfying answer (e.g. this and this are not what I am looking for).


I'd like to get an overline over a symbol, but not over its subscript. Though this is no problem, the grouping destroys the kerning of the subscript. Consider the example:

enter image description here

How can I get the overline just over f like in the second line, but the kerning of the subscript of the first line?

Of course I could adjust it manually with negative spacing, but I wonder if there is a more generic solution.

MWE

\documentclass{article}

\usepackage{amsmath}
\usepackage{helvet}
\usepackage{sansmathfonts}

\begin{document}

without overline:
\[f_t\]
with overline and subscript outside:
\[\overline{f}_t\]
with overline and subscript inside:
\[\overline{f_t}\]

\end{document}

1 Answer 1

7

You can use \bar or adjust the space after \overline

enter image description here

\documentclass{article}

\usepackage{amsmath}
\usepackage{helvet}
\usepackage{sansmathfonts}

\begin{document}

without overline:
\[f_t\]
with overline and subscript outside:
\[\overline{f}_t\]
with overline and subscript inside:
\[\overline{f_t}\]
with bar and subscript outside:
\[\bar{f}_t\]
with adjusted overline
\setbox0\hbox{$f_t$}
\setbox2\hbox{$\overline{f}_t$}
\[\overline{f}\kern\dimexpr\wd0-\wd2\relax_t\]
\end{document}

If you need this more than once, something like

\newcommand\mean[2][]{%
  \overline{#2}%
   \ifx\relax#1\relax\else
   \sbox0{$#2_{#1}$}%
   \sbox2{$\overline{#2}_{#1}$}%
   \kern\dimexpr\wd0-\wd2\relax_{#1}%
   \fi}

with macro
\[\mean[t]{f}\]
3
  • @thewaywewalk obviously if doing this more than once you would wrap the measuring in a two argument macro use (although personally I think I'd use \bar) Commented Jan 3, 2017 at 11:04
  • 1
    @thewaywewalk no that is wrong, \bar (unlike \overline) is a fixed font glyph the length does not depend on the width of the base. But I added a macro version for \overline to the answer. Commented Jan 3, 2017 at 11:12
  • You're right, I got confused. However a fixed length is also not desirable for my case. Thanks for the macro! Commented Jan 3, 2017 at 11:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .