71

Not sure if LaTeX counts as programming, or if my question even makes sense, but I have this LaTeX expression (or what you call it):

\sum_{k=1}^n k^2 = 1+4+9+\ldots +n^2 =
\frac{1}{3}n^3 + \frac{1}{2}n^2 + \frac{1}{6}n

The problem is that the k=1 and n comes next to, i.e. after, the sum symbol, instead of above and below it. Is there a way I can change this? I have tried to show visually what I mean below. The sum symbol represented as Xs :

 n
XXX          XXX n
XXX    vs    XXX
XXX          XXX k=1
k=1

I want the first kind, but am getting the second.

1

3 Answers 3

118

Try

\sum\limits_{k=1}^n k^2

if you want the sum limits to appear above and below the sum sign in an inline equation.

2
  • Umm.. Can I ask a question? Do I only need to do this if the sum sign is in an inline equation? As far as I can tell I should also be able to use this without \limits in an inline equation. Am I wrong? Nov 17, 2010 at 0:32
  • @the_great_monkey: Yes, you can leave out the \limits in an inline equation, but then the limits will be displayed to the right of the equation instead of above and below it. In a display equation, the limits will always be displayed above and below, regardless of whether or not you use \limits.
    – Martin B
    Dec 6, 2010 at 11:04
29

A more general solution to force a formula that is appearing in inline style to appear in display style is to start the formula with a \displaystyle declaration, e.g.

$\displaystyle \sum_{k=1}^n k^2$

This will work for any expression that appears differently in inline and display environments, such as \frac, \int, \lim, etc. You can also control the scope of the \displaystyle command by enclosing the desired expression in braces. For example, if you want the sum in your example formula to appear in display style but not the fractions, you could use

${\displaystyle \sum_{k=1}^n k^2} = 1+4+9+\ldots +n^2 = 
\frac{1}{3}n^3 + \frac{1}{2}n^2 + \frac{1}{6}n$
2
  • That probably works too, but the WordPress Latex plugin doesn't seem to support it. It says that I must stay in inline math mode. Maybe that's why the \begin{equation} stuff doesn't work either...
    – Svish
    Sep 25, 2009 at 6:28
  • I'm pretty sure that the WordPress LaTeX plugin does support \displaystyle because I've used it on my blog on wordpress.com An example drawn directly from my blog is $latex \displaystyle \frac{n^2 - 1}{n^2 + 2} = \frac{4 \pi}{3} N \alpha_i$
    – las3rjock
    Sep 25, 2009 at 8:28
-1

I think you will need to use the equation environment for that:

\begin{equation}
\sum_{k=1}^n k^2 = 1+4+9+\ldots +n^2 = \frac{1}{3}n^3 + \frac{1}{2}n^2 + \frac{1}{6}n
\end{equation}
3
  • Hm, probably correct, but the WP Latex plug-in says that the formula does not parse. For some reason...
    – Svish
    Sep 24, 2009 at 11:27
  • Hm, yeah, that could be. I didn't test is, just copied the formula given in the question... Sep 24, 2009 at 11:30
  • 1
    You are half-right here - \sum defaults to limits on the side when inline, and limits above and below when not (equation environment, $$). Martin B's answer, using \limits, will force it to place them above and below independent of environment.
    – Cascabel
    Sep 24, 2009 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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