Sum within a fraction

I'm trying to get a sum to display "properly" within a fraction. My input is:

\begin{equation}
E = 1 - \dfrac{\sum_{i=1}^{n}(O_{i}-P_{i})^{2}}{\sum_{i=1}^{n}(O_{i}-\bar{O})^{2}}
\end{equation}

And the output looks like this: I want the indices to appear above and below the sum as opposed to the side. How can I go about doing this?

• This is the proper way, in order to save some vertical space.
– yo'
Jun 9 '14 at 13:23

Use \limits just before _ and ^ in connection with \sum command, the same holds also for an integral \int\limits^{b}_{a} for example.

\documentclass[paper=a4,12pt]{book}

\usepackage{amsmath}
\begin{document}

\begin{equation}
E = 1 - \dfrac{\sum\limits_{i=1}^{n}(O_{i}-P_{i})^{2}}{\sum\limits_{i=1}^{n}(O_{i}-\bar{O})^{2}}
\end{equation}

\end{document} • But shouldn't \dfrac make both numerator and denominator in \displaystyle mode? Jun 9 '14 at 13:23
• @Manuel: Yes, that is true, see tex.stackexchange.com/questions/135389/…, but as far as I know \displaystyle mode has no effect on the positioning of limits of sum or integral symbols
– user31729
Jun 9 '14 at 13:35
• No, in fact it doesn't have to make both of them \displaystyle. If I'm not mistaken it just makes the whole fraction \displaystyle (therefore, the two parts are \textstyle). Jun 9 '14 at 13:43
• There is no need for \dfrac; here, \frac suffice. Jun 11 '14 at 7:49
• @SvendTveskæg: I just used it from the 'MWE' above
– user31729
Jun 11 '14 at 7:50