I want to write this in LaTeX:


However, $$\overline{S_n}^2 = \frac{1}{n}\sum\limits_{i=1}^{n}(X_i - M_n)^2$$ gives me:


whereas $$\bar{S_n}^2 = \frac{1}{n}\sum\limits_{i=1}^{n}(X_i - M_n)^2$$ gives me:


How can I fix this?

  • 1
    Put the subscript outside the \overline: \overline{S}_n^2. BTW, use \[...\] instead of $$...$$. However, my personal preference would be \bar{S}_n^2 (definitely not \bar{S_n}^2 with the subscript inside). – Ruixi Zhang Jan 22 at 13:06

Hope the below code may helps you...







enter image description here


Using Hendrik Vogt's code in his answer to this question, you have a \widebar command which takes into account the italic angle of the glyph:

    \usepackage{mathtools, nccmath}

  \ifdim\ht0=\ht2 #3\else #2\fi
%The bar will be moved to the right by a half of \macc@kerna, which is computed by amsmath:
%If there's a superscript following the bar, then no negative kern may follow the bar;
%an additional {} makes sure that the superscript is high enough in this case:
%Use a separate algorithm for single symbols:
%Enable nesting of accents:
%If there's more than a single symbol, use the first character instead (see below):
    \if#32 \let\macc@nucleus\first@char \fi
%Determine the italic correction:
%Now \dimen@ is the italic correction of the symbol.
    \divide\dimen@ 3
%Now \@tempdima is the width of the symbol.
    \divide\@tempdima 10
%Now \dimen@ = (italic correction / 3) - (Breite / 10)
    \ifdim\dimen@>\z@ \dimen@0pt\fi
%The bar will be shortened in the case \dimen@<0 !
%Place the combined final kern (-\dimen@) if it is >0 or if a superscript follows:
      \ifdim\dimen@<\z@ \let\final@kern1\fi
      \if\final@kern1 \kern-\dimen@\fi
  \let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar
  \mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}%
%The following initialises \macc@kerna and calls \mathaccent:
%If the argument consists of more than one symbol, and if the first token is
%a letter, use that letter for the computations:
    \ifcat\noexpand\first@char A\else


    \[ \widebar{S}_n^2 = \mfrac{1}{n}\sum_{i=1}^{n}(X_{i} - M_{n})^{2} \]%



I would say



  $$\overline{S}_n^2 = \frac{1}{n}\sum\limits_{i=1}^{n}(X_i - M_n)^2$$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.