I'm trying to add the moving average equation, but keep getting errors saying: 1. missing $ inserted 2. runaway argument? 3. missing } 4. undefined control sequence despite the error my equation does show up, but give me me alot of errors in the log

\centering \overline{P}SM= \frac{PM + PM-1 + ...+PM -(n-1)} {{n}\frac{n}}
\frac{1}{n} = \sum_{i=0}^{n-1} PM-i
\end{equation} \label{Movingavg

I want it to look like this:

enter image description here

  • 1
    try inserting the \overline.......} inside $...$ if you prefer inline math, or encapsulate it within \[...\] if you prefer display styled equation. And, you can remove the \centering before the math, if you would prefer the display style. Also, next time please post a MWE. The errors are because of the fact that you are using math outside it's designated environments. And, remove the \frac{n} or add the denominator part of fraction \frac{num}{den}. – Raaja_is_at_topanswers.xyz Nov 1 '18 at 19:20

Is this what you want, per chance?



\overline{\!P}SM= \frac{PM + PM-1 + ...+PM -(n-1)} {n} \\
\frac{1}{n} = \sum_{i=0}^{n-1} PM-i


enter image description here


You need something like this:

\overline{p}_\text{SM} &= \frac {p_M + p_{M-1} + \cdots + p_{M-(n-1)}}{n}\\
                       &= \frac 1n \sum_{i=0}^{n-1} p_{M-i}

enter image description here


  • the SM is an abbrev. for simple moving average, so it is better written in text mode
  • all subscripts _M through _{M-i} are written using the underscore _ they are not multiplied by p
  • the two lines can be aligned at = and combined using the aligned construct
  • the \frac{1}{n} can be reduced as \frac1n
  • as a final note, you may want to lower the subscripts a bit more to be clear, this can be easily done by adding an extra empty ^{} like this: p_M^{} + p_{M-1}^{} + \cdots + ..., etc., which would output:

enter image description here

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.