LaTeX Summation: Sum Limits, \substack and Double Sums

November 11, 2026 · 9 min read

LaTeX Summation: Write Sums with Limits Above and Below

A LaTeX summation uses the \sum command in math mode, with the lower limit after _ and the upper limit after ^: \sum_{i=1}^{n} a_i. In display math the limits sit above and below the sign. Inline, they move to the side, and \limits or \displaystyle stacks them again.

Below you'll build a sum in LaTeX from a basic range up to stacked conditions and double sums, and see why \Sigma is the wrong command. Each section flags what needs a compiled .tex file and what also renders in KaTeX-powered Markdown.

LaTeX Summation Basics: \sum with _ and ^

Every LaTeX summation starts with \sum, and the command only works in math mode. Put the lower limit in a subscript and the upper limit in a superscript, and wrap any limit longer than one character in braces.

\sum_{i=1}^{n} a_i

In display math this renders as a large sigma with i=1 below it and n above it:

∑i=1nai\sum_{i=1}^{n} a_i

The braces matter. \sum_{i=1}^{10} i sums the numbers 1 to 10, but \sum_i=1^10 attaches only i to the sign, prints =1 beside it and raises the first digit of 10 alone. LaTeX reads only the next single token as the subscript or superscript unless you group it.

Limits are optional. \sum_i x_i shows only an index, and a bare \sum x_i means "sum over everything in context". For an infinite series, write the upper limit as ^{\infty}, as in \sum_{k=0}^{\infty}. Our LaTeX infinity symbol guide shows \infty in limits and improper integrals too.

Why Do Sum Limits Move to the Side in Inline Math?

TeX typesets math in four styles, and the two that matter here are display style and text style. A displayed formula, such as \[...\] or an equation environment, uses display style. An inline formula inside $...$ uses text style, which shrinks the sign and moves the limits to the right.

That's deliberate. The LaTeX2e reference manual on math styles explains that side limits keep the formula from pushing the surrounding lines apart. The amsmath user guide calls this default "displaylimits" positioning for sum-class symbols.

Markdown follows the same rule. A single $ gives you inline text style and $$ gives you display style. Our guide to writing equations in Markdown covers the delimiters and which platforms support them. In our editor, use $ and $$ only, because the \(...\) and \[...\] delimiters aren't supported there.

Here's the same source in both modes. Inline: ∑i=1nai\sum_{i=1}^{n} a_i. Display:

∑i=1nai\sum_{i=1}^{n} a_i

How Do You Put Limits Above and Below a Sum?

You have two fixes for an inline sum, plus the option of moving it into display math.

$\sum\limits_{i=1}^{n} a_i$
$\displaystyle\sum_{i=1}^{n} a_i$

The first line keeps the text-size sign and stacks the limits above and below it. The second switches the rest of the formula to display style, so you get the full-size sign, stacked limits and larger fractions too.

Rendered inline, the difference looks like this: ∑i=1nai\sum\limits_{i=1}^{n} a_i versus ∑i=1nai\displaystyle\sum_{i=1}^{n} a_i.

We prefer \limits for inline sums. It keeps the small sign, so the line grows only by the height of the limits. The \displaystyle version looks bolder, but its full-size sign pushes the lines above and below further apart. If the sum is that important, give it its own display block instead.

The same limit rules apply to \prod, \bigcup and the other sum-class operators. Integrals are the exception: \int keeps its limits to the side even in display math unless you add \limits. Our LaTeX symbols reference lists the product and integral commands, with a KaTeX column for each.

How Do I Write a Small Summation in LaTeX?

Sometimes you want the opposite: a compact summation in LaTeX display math. Use \nolimits to put the limits beside the sign, or \textstyle to shrink the whole sign.

\[ \sum\nolimits_{i=1}^{n} a_i \]
\[ \textstyle\sum_{i=1}^{n} a_i \]

The first keeps the large sign with side limits. The second renders exactly like an inline sum, small sign included:

∑i=1nai∑i=1nai\sum\nolimits_{i=1}^{n} a_i \qquad \textstyle\sum_{i=1}^{n} a_i

Often you don't need either. The numerator and denominator of a displayed \frac are already set in text style, so a sum there gets side limits on its own. The same happens inside matrix cells, which matters if you put sums in the entries of a Markdown matrix.

Multiple Conditions Under a Sum with \substack

When one subscript line isn't enough, \substack stacks several conditions, separated by \\:

\sum_{\substack{1 \le i \le n \\ i \ne j}} a_{ij}
∑1≤i≤ni≠jaij\sum_{\substack{1 \le i \le n \\ i \ne j}} a_{ij}

In a .tex file, \substack comes from the amsmath package, so add \usepackage{amsmath} to the preamble. Its sibling, the subarray environment, does the same job with left-aligned lines: \begin{subarray}{l} ... \end{subarray}. KaTeX supports both, and so does MathJax, so you don't load anything in Markdown.

Conditions don't have to be ranges. \sum_{x \in S} f(x) sums over a set, and \sum_{p \text{ prime}} \frac{1}{p^2} uses \text for words. In LaTeX, \text also needs amsmath.

∑x∈Sf(x)∑p prime1p2\sum_{x \in S} f(x) \qquad \sum_{p \text{ prime}} \frac{1}{p^2}

Double Sums and Wide Limits

A double LaTeX summation is just two \sum commands placed side by side:

\sum_{i=1}^{m} \sum_{j=1}^{n} a_{ij}
∑i=1m∑j=1naij\sum_{i=1}^{m} \sum_{j=1}^{n} a_{ij}

When both indices run over the same range, a compact \sum_{i,j} a_{ij} is common. Some authors add a thin space \, between the two signs, but it's optional.

Long limits cause a different problem. In \sum_{1 \le i \le j \le n} X_{ij}, the wide subscript pushes the neighboring symbols away from the sign. The mathtools package fixes this with \mathclap, which centers the limit in a zero-width box:

X = \sum_{\mathclap{1 \le i \le j \le n}} X_{ij}
X=∑1≤i≤j≤nXijX = \sum_{\mathclap{1 \le i \le j \le n}} X_{ij}

KaTeX supports \mathclap too. Mathtools also offers \smashoperator, and amsmath has \sideset for corner marks on an operator. Neither one is in KaTeX, so a KaTeX-based preview shows red error text or the raw command instead of the formula. Keep them for documents you compile with LaTeX, or check your renderer's docs first. That's the main limitation of writing sums for the web: KaTeX covers a large subset of these packages, not all of it.

\sum vs \Sigma: Operator or Greek Letter?

The symbol ∑ is the summation operator, a capital sigma that means "add up these terms". The LaTeX sum symbol is \sum, never \Sigma. They're different characters: Unicode lists ∑ as U+2211 N-ARY SUMMATION and Σ as U+03A3 GREEK CAPITAL LETTER SIGMA. To learn how to read the notation itself, see our guide to sigma summation notation.

The difference shows as soon as you add limits:

\sum_{k=1}^{n} k \qquad \Sigma_{k=1}^{n} k
∑k=1nkΣk=1nk\sum_{k=1}^{n} k \qquad \Sigma_{k=1}^{n} k

\sum is a large operator, so it grows in display math and stacks its limits. \Sigma is an ordinary letter. It stays at text height and puts k=1 and n to its right as plain subscript and superscript, even in a display block. Use \Sigma for things named with the letter, such as a covariance matrix, and reach for \sum whenever you add terms. The other capital letters are in our table of LaTeX Greek symbols.

Try the pieces together below. The demo holds an inline sum, the \limits fix, a \substack sum, a double sum and the \Sigma trap. Change any limit and the live preview updates.

Inline sum: ∑i=1nai\sum_{i=1}^{n} a_i and with limits: ∑i=1nai\sum\limits_{i=1}^{n} a_i

Display sum with two conditions:

∑1≤i≤m1≤j≤naij\sum_{\substack{1 \le i \le m \\ 1 \le j \le n}} a_{ij}

Double sum:

∑i=1m∑j=1naij\sum_{i=1}^{m}\sum_{j=1}^{n} a_{ij}

Operator vs letter: ∑k=1nk\sum_{k=1}^{n} k vs Σk=1nk\Sigma_{k=1}^{n} k

42 words294 characters15 lines
Markdown

LaTeX Summation Formulas to Copy

Each formula below renders in both LaTeX and KaTeX. Paste the formula between the $$ lines into the LaTeX equation editor to export it as PNG or SVG, or to copy it as a Markdown math snippet.

$$
\sum_{k=0}^{n-1} ar^k = a\frac{1-r^n}{1-r}
$$

$$
\sum_{k=0}^{\infty} ar^k = \frac{a}{1-r}, \quad |r| < 1
$$

$$
\sum_{k=1}^{n} k^2 = \frac{n(n+1)(2n+1)}{6}
$$

$$
\sum_{k=1}^{n} k^3 = \left(\frac{n(n+1)}{2}\right)^2
$$

They render as a finite geometric series, an infinite geometric series with its convergence condition, the sum of squares and the sum of cubes:

∑k=0n−1ark=a1−rn1−r∑k=0∞ark=a1−r,∣r∣<1∑k=1nk2=n(n+1)(2n+1)6∑k=1nk3=(n(n+1)2)2\begin{gathered} \sum_{k=0}^{n-1} ar^k = a\frac{1-r^n}{1-r} \\ \sum_{k=0}^{\infty} ar^k = \frac{a}{1-r}, \quad |r| \lt 1 \\ \sum_{k=1}^{n} k^2 = \frac{n(n+1)(2n+1)}{6} \\ \sum_{k=1}^{n} k^3 = \left(\frac{n(n+1)}{2}\right)^2 \end{gathered}

The same blocks work in Jupyter Markdown cells. Our Jupyter Markdown cheat sheet covers the rest of the cell syntax. The KaTeX supported functions list is the place to check any other command before you rely on it in Markdown.

A LaTeX summation comes down to three choices: the limits after _ and ^, where they sit, and how many conditions go underneath. Start with \sum_{i=1}^{n}, then reach for \limits inline and \substack for extra conditions. Paste any $ or $$ example from this page into the editor to check how it renders before you use it.