[Tex/LaTex] Symbol with overline and subscript leads to wrong kerning

amsmathkerningsubscriptssymbols

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}

Best Answer

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}\]