# \overline with subscripts [duplicate]

I would like to write

 \overline{Y}_n


in order to display the mean of Y. This yields:

However when I do this there is a gap between the Y and the n. Using

\bar{Y}_n


yields:

This avoids the gap however in that case the bar above the Y is not long enough for my liking.

I have seen that there exists a question \overline and \widehat with subscript but that question asks about subscript added to the bar symbol, not subscript added to the symbol(s) which are under the bar.

I'm also aware of this question: Overline over a symbol with an index but that question is about what you should or shouldn't do; not a method to solve this problem.

EDIT: I realize that this question is very similar to this one: Symbol with overline and subscript leads to wrong kerning, however the answer given below is better than the ones to that question.

• The simplest fix would be \overline{Y}_{\!n}, but it requires a little typing. – Steven B. Segletes May 17 '17 at 11:45
• @Arzigoglu yeah they're quite similar, though I prefer the answer given below to this question, I'm not sure what the proper thing is to do in this case. – Sam Davenport May 17 '17 at 12:11
• @hallomotocar you should see my answer more like a quick fix. If you want exact results (meaning same spacing as without the \overline), you should either use the answer provided in the question Arzigoglu linked to or use AboAmmar's answer. – Skillmon May 17 '17 at 12:28

Exact method with a newcommand:

\documentclass{article}
\begin{document}

\newcommand{\mybar}[1]{\makebox[0pt]{$\phantom{#1}\overline{\phantom{#1}}$}#1}

\noindent
$Y_n$ ... with no bar \\
$\mybar{Y}_n$ ... with my bar

\end{document}


You could insert a negative space \! to reduce the spacing:

\documentclass[draft]{scrartcl}

\begin{document}
\noindent
$\overline{Y}_n$\\
$\overline{Y}_{\!n}$\\
$Y_n$\\
$\overline{Y_n}$
\end{document}