# Variance formula does not display correctly

\begin{document}
\sigma^2=\frac{\sum(X -\mu)^2}\limits_{i=1}^N{N}
\end{document}


This is the code I am using to display variance formula, but it displays

How should I correct it?

• (1) Always post fully compilable examples, not sniplets, (2) then you would not that that sniplet dows not compile, as it is marh, and math mode has not been initiated. (3) It might be a good idea to read an introduction to LaTeX, e.g. the lshort document on CTAN in order to know the difference between displayed math and inline math. Sep 18 '15 at 6:33
• @daleif, but this is all the code I have! and it compiles in MikTeX. Thanks for the idea,though, I would surely read the introduction. Sep 18 '15 at 6:35
• That does not compile in even in MikTeX, there is no \documentclass! You also got the syntax all wrong. \limits has no place here, use \sum_{lower}^{\upper} ... Sep 18 '15 at 6:39
• I assume there is a lot I don't know in LaTex, but I got the first figure from my TexWorks output (which uses MikTeX). It gave the pdf output, though with a lot of error messages, and that's what I meant by compiled. Sep 18 '15 at 6:47
• That is not what compiled means. If you compile this by hand, using pdflatex file.tex in a dos promt, you will notice that it will fail. Most editors run LaTeX in a mode that does not stop at errors, it makes an assumption and tries to continue. That is why your document seems to compile, in that it gives a PDF. But a document that does not compile withput errors, does, by doefinition, not compile. Sep 18 '15 at 6:58

Your MWE can not work! For math expression you need math environment, for inline formulas $... your math expression ...$, for display formula (stand alone in text) $$....$$ for numbered equations and for non-numbered $...$. For math environments exist other possibilities, which available with us packets as amsmath etc.

Also the formula is ill formed. Correct code is:

\documentclass[border=3mm,
preview]{standalone}% or any other document class, as article, book ..
\begin{document}
$\sigma^2 = \frac{\sum\limits_{i=1}^N (X -\mu)^2}{N}$
\end{document}


which gives:

• What is {standalone}? I don't have it in my MikTeX, it prompts me to install. Sep 18 '15 at 6:53
• just replace it with article, standalone is not suppose to be used in normal user documents Sep 18 '15 at 6:59
• @JasonStack, standalone is wonderfull package and document class intended to show text, figures, etc on whole "page", actually, it accommodate size of page to content. It is worth to install it, read a documentation for all possibilities and than exploit its possibilities. Given MWE also works (as I mentioned in comment in code) if you replace it withdocumentclass{article}. Sep 18 '15 at 7:00
• Thanks @Zarko, standalone and preview packages are really cool! I just installed them and got big previews with adjustable zoom for the output. Sep 18 '15 at 7:23

Here is a better MWE:

\documentclass[a4paper]{article}
\begin{document}
$\sigma^2=\frac{\sum_{i=1}^N (X -\mu)^2}{N}$
\end{document}