0
\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 enter image description here
instead of

enter image description here

How should I correct it?

5
  • (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.
    – daleif
    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.
    – djnotes
    Sep 18 '15 at 6:35
  • 2
    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} ...
    – daleif
    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.
    – djnotes
    Sep 18 '15 at 6:47
  • 2
    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.
    – daleif
    Sep 18 '15 at 6:58
2

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) \begin{equation} .... \end{equation} 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:

enter image description here

4
  • What is {standalone}? I don't have it in my MikTeX, it prompts me to install.
    – djnotes
    Sep 18 '15 at 6:53
  • 1
    just replace it with article, standalone is not suppose to be used in normal user documents
    – daleif
    Sep 18 '15 at 6:59
  • 1
    @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}.
    – Zarko
    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.
    – djnotes
    Sep 18 '15 at 7:23
6

Here is a better MWE:

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

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.