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.

Martin B
  • 23,670
  • 6
  • 53
  • 72
Svish
  • 152,914
  • 173
  • 462
  • 620

3 Answers3

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.

Martin B
  • 23,670
  • 6
  • 53
  • 72
  • 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? – Enrico Susatyo Nov 17 '10 at 00: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 06 '10 at 11:04
28

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$
las3rjock
  • 8,612
  • 1
  • 31
  • 33
  • 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 '09 at 06:28
  • I'm pretty sure that the WordPress LaTeX plugin does support \displaystyle because I've used it on my blog on http://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 '09 at 08: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}
unwind
  • 391,730
  • 64
  • 469
  • 606
user254875486
  • 11,190
  • 7
  • 36
  • 65
  • Hm, probably correct, but the WP Latex plug-in says that the formula does not parse. For some reason... – Svish Sep 24 '09 at 11:27
  • Hm, yeah, that could be. I didn't test is, just copied the formula given in the question... – user254875486 Sep 24 '09 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 '09 at 12:34