# \substack

Stacking short expressions on multiple lines, typically inside subscripts, superscripts, or under limit operators.

https://texform.dev/latex/commands/substack

## Metadata

| Field | Value |
| --- | --- |
| Topic | [Large operators](https://texform.dev/latex/topics/operators-limits) |
| Packages | ams |
| Allowed mode | math |
| Tags |  |
| Commonality | medium |
| Kind | prefix |

## Syntax

### ams

Argument specification: `m`

Stacking short expressions on multiple lines, typically inside subscripts, superscripts, or under limit operators.

## Common tasks

### How to write a two-line subscript on a sum

```latex
\sum_{\substack{i=1\\i\neq j}}^n a_{ij}
```

[Open in Playground](https://play.texform.dev/?input=%5Csum_%7B%5Csubstack%7Bi%3D1%5C%5Ci%5Cneq+j%7D%7D%5En+a_%7Bij%7D)

### How to write several constraints under a max

```latex
\max_{\substack{x\ge 0\\ \|x\|_1=1}} f(x)
```

[Open in Playground](https://play.texform.dev/?input=%5Cmax_%7B%5Csubstack%7Bx%5Cge+0%5C%5C+%5C%7Cx%5C%7C_1%3D1%7D%7D+f%28x%29)

### How to stack conditions under a union

```latex
\bigcup_{\substack{n\in\mathbb{N}\\ n\text{ odd}}} A_n
```

[Open in Playground](https://play.texform.dev/?input=%5Cbigcup_%7B%5Csubstack%7Bn%5Cin%5Cmathbb%7BN%7D%5C%5C+n%5Ctext%7B+odd%7D%7D%7D+A_n)

## Examples

```latex
\substack{a\\b}
```

[Open in Playground](https://play.texform.dev/?input=%5Csubstack%7Ba%5C%5Cb%7D)

## Renderer support

| Package | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- |
| ams | full | full | full |

## Usage frequency

0.62% of formulas in the measured corpus contain this entry, rank 57 of 263 entries with frequency data.

## In TeXForm

TeXForm parses this entry as prefix syntax; the package determines its argument specification.

### Expands to (ams)

```latex
\substack{#1}
```

→

```latex
\begin{subarray}{c}#1\end{subarray}
```

The replacement hardcodes a single centered column and reparses the body as `subarray` content.

### [ams/substack-expand](https://texform.dev/rules/ams/substack-expand)

Expand substack directly to the explicit centered subarray environment.

Level: faithful. Fidelity: render.

```latex
\substack{#1\\#2}
```

→

```latex
\begin{subarray}{c}#1\\#2\end{subarray}
```

```latex
\sum_{\substack{1\le i\le n\\ i\text{ odd}\\ i\ne 5}} a_i
```

→

```latex
\sum_{\begin{subarray}{c}1\le i\le n\\ i\text{ odd}\\ i\ne 5\end{subarray}} a_i
```

## See also

- [\\bmod](https://texform.dev/latex/commands/bmod)
- [\\bmqty](https://texform.dev/latex/commands/bmqty)
- [\\boxed](https://texform.dev/latex/commands/boxed)
- [\\bra](https://texform.dev/latex/commands/bra)
- [\\Bra](https://texform.dev/latex/commands/Bra)
- [\\flatfrac](https://texform.dev/latex/commands/flatfrac)
- [\\iff](https://texform.dev/latex/commands/iff)
- [\\imathbb](https://texform.dev/latex/commands/imathbb)
- [\\imathbfbb](https://texform.dev/latex/commands/imathbfbb)
- [\\impliedby](https://texform.dev/latex/commands/impliedby)
- [\\implies](https://texform.dev/latex/commands/implies)
- [\\itextbb](https://texform.dev/latex/commands/itextbb)
- [\\itextbfbb](https://texform.dev/latex/commands/itextbfbb)
- [\\jmathbb](https://texform.dev/latex/commands/jmathbb)
- [\\jmathbfbb](https://texform.dev/latex/commands/jmathbfbb)
- [\\jtextbb](https://texform.dev/latex/commands/jtextbb)
- [\\jtextbfbb](https://texform.dev/latex/commands/jtextbfbb)
- [\\ket](https://texform.dev/latex/commands/ket)
- [\\Ket](https://texform.dev/latex/commands/Ket)
- [\\ketbra](https://texform.dev/latex/commands/ketbra)
- [\\Ketbra](https://texform.dev/latex/commands/Ketbra)
- [\\LaTeX](https://texform.dev/latex/commands/LaTeX)
- [\\mathstrut](https://texform.dev/latex/commands/mathstrut)
- [\\matrixdeterminant](https://texform.dev/latex/commands/matrixdeterminant)
- [\\mdet](https://texform.dev/latex/commands/mdet)
- [\\mod](https://texform.dev/latex/commands/mod)
- [\\pmb](https://texform.dev/latex/commands/pmb)
- [\\pmod](https://texform.dev/latex/commands/pmod)
- [\\pmqty](https://texform.dev/latex/commands/pmqty)
- [\\Pmqty](https://texform.dev/latex/commands/Pmqty)
- [\\pod](https://texform.dev/latex/commands/pod)
- [\\qc](https://texform.dev/latex/commands/qc)
- [\\qcomma](https://texform.dev/latex/commands/qcomma)
- [\\Residue](https://texform.dev/latex/commands/Residue)
- [\\sbmqty](https://texform.dev/latex/commands/sbmqty)
- [\\skew](https://texform.dev/latex/commands/skew)
- [\\smdet](https://texform.dev/latex/commands/smdet)
- [\\spmqty](https://texform.dev/latex/commands/spmqty)
- [\\sPmqty](https://texform.dev/latex/commands/sPmqty)
- [\\stackbin](https://texform.dev/latex/commands/stackbin)
- [\\stackrel](https://texform.dev/latex/commands/stackrel)
- [\\svmqty](https://texform.dev/latex/commands/svmqty)
- [\\TeX](https://texform.dev/latex/commands/TeX)
- [\\textbf](https://texform.dev/latex/commands/textbf)
- [\\textit](https://texform.dev/latex/commands/textit)
- [\\textnormal](https://texform.dev/latex/commands/textnormal)
- [\\textrm](https://texform.dev/latex/commands/textrm)
- [\\textsf](https://texform.dev/latex/commands/textsf)
- [\\texttt](https://texform.dev/latex/commands/texttt)
- [\\textup](https://texform.dev/latex/commands/textup)
- [\\varinjlim](https://texform.dev/latex/commands/varinjlim)
- [\\varliminf](https://texform.dev/latex/commands/varliminf)
- [\\varlimsup](https://texform.dev/latex/commands/varlimsup)
- [\\varprojlim](https://texform.dev/latex/commands/varprojlim)
- [\\vmqty](https://texform.dev/latex/commands/vmqty)
- [\\zeromatrix](https://texform.dev/latex/commands/zeromatrix)
- [\\zmat](https://texform.dev/latex/commands/zmat)

## Test cases

### ams

| Input | Case | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- | --- |
| \substack{a} | Positive: baseline | Pass | Pass | Pass |
| \substack a | Positive: bare[0] | Pass | Pass | Pass |
