To place a cases block between aligned steps in one LaTeX equation, put cases inside a row of aligned, then wrap the whole structure in equation. This keeps the equals signs aligned and gives the complete derivation one equation number.
This guide is for someone editing a .tex document on a Mac who wants ordinary algebraic steps above and below a piecewise expression. The main example uses only amsmath; the alternatives explain when mathtools or independently centered blocks are appropriate.
How do you keep the steps and cases in one aligned equation?
Use three nested levels: equation contains the complete display, aligned arranges the derivation, and cases supplies the braced expression in one row. The official guide describes aligned as a building block that fits within a containing expression and requires both aligned and cases to appear in math mode. See section 3.7 of the User’s Guide for the amsmath Package.
Here is a complete document. Let n be an integer and a be a scalar. The expression has the value a whether n is even or odd; the cases block makes that intermediate reasoning visible.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Let \(n\) be an integer and \(a\) be a scalar.
\begin{equation}
\label{eq:cases-chain}
\begin{aligned}
S(n) &= a\bigl[(-1)^n+1-(-1)^n\bigr] \\
&= a(-1)^n+a\bigl(1-(-1)^n\bigr) \\
&= \begin{cases}
a+0, & \text{if } n \text{ is even}, \\
-a+2a, & \text{if } n \text{ is odd}
\end{cases} \\
&= a.
\end{aligned}
\end{equation}
The result is recorded in \eqref{eq:cases-chain}.
\end{document}
Read the example as four outer rows. The first two expand the expression, the third evaluates it by parity, and the fourth gives the shared result. Both branches reduce to a, so the final equality applies to every integer n. This algebra is illustrative; replace it with the expressions and conditions from your own derivation.
Which ampersands and line breaks belong to which environment?
The outer &= marks the alignment point before each equals sign. Inside cases, the ampersand separates a branch expression from its condition. The two levels have separate jobs: the cases block occupies part of one outer row, even though it contains multiple branch rows. The package implements cases as a two-column array with a left brace, as shown in the amsmath package documentation.
The crucial transition in this example is \end{cases} \\. Closing cases finishes the piecewise expression; the following \\ finishes the surrounding aligned row. The next &= a can then begin beneath the earlier equals signs. A line break inside cases only moves to another branch.
When adapting the example, preserve that structure first. Change one branch expression or condition at a time, then inspect the result. This makes it easier to identify whether an unexpected layout comes from the surrounding derivation or the piecewise expression itself.
How do you use the example on a Mac?
You need a working LaTeX distribution and a source editor. If you already use TeXShop, it provides an editor and PDF preview and uses TeX Live for typesetting. Its default PDF workflow uses pdftex and pdflatex, according to the developer’s About TeXShop page.
- Create a new source document and paste the complete example.
- Save it as
cases-between-steps.tex. - Use a LaTeX typesetting engine, such as
pdflatex. - Choose
Typesetfrom TeXShop’sTypesetmenu. That command typesets the current document, as documented in the TeXShop Changes. - Typeset again if the equation reference is unresolved, then inspect the PDF.
Check three features in the preview: the outer equals signs form one vertical column, the brace covers only the two branches, and the derivation has one equation number. Also read both conditions and the final line to confirm that the mathematics survived the edit.
These examples were inspected against the documentation but were not compiled here because a LaTeX engine was unavailable. Try the small standalone document before incorporating it into a larger project.
Which environments and packages should you choose?
Choose the outer structure according to the relationship between the steps. For one continuous equality chain, keep one shared alignment. For separate groups that only need to appear above and below a cases block, use the independently centered alternative in the next section.
| Desired result | Structure | Package |
|---|---|---|
| Shared equals-sign alignment and one number | equation containing aligned, with nested cases |
amsmath |
| Independently centered groups and one number | equation containing gathered, with nested blocks |
amsmath |
| Larger fractions throughout the cases rows | Replace cases with dcases |
mathtools |
| Automatically textual conditions | Use cases* or dcases* |
mathtools |
The compact building blocks are documented in the amsmath user guide; the additional cases variants are documented in section 3.4.3 of The mathtools package.
When should you replace cases with dcases?
Ordinary cases uses text-style mathematics. The mathtools environment dcases uses display style, which is useful when fractions need more room. Loading mathtools also loads amsmath. The starred variant dcases* makes the second column textual; put mathematical conditions in inline math delimiters there. These behaviors are documented in The mathtools package.
This complete alternative uses fractions. For integer n, the denominator in the first line is either three or one, so both branches are defined.
\documentclass{article}
\usepackage{mathtools}
\begin{document}
Let \(n\) be an integer and \(a\) be a scalar.
\begin{equation}
\begin{aligned}
T(n) &= \frac{2a}{2+(-1)^n} \\
&= \begin{dcases}
\frac{2a}{3}, & \text{if } n \text{ is even}, \\
2a, & \text{if } n \text{ is odd}
\end{dcases} \\
&= \frac{a}{1+\frac{1}{2}(-1)^n}.
\end{aligned}
\end{equation}
\end{document}
Here, changing the branch style leaves the outer layout intact. Choose cases for compact branches and dcases when the fractions benefit from display style. With cases or dcases, keep prose inside \text{...}; with the starred variants, write prose directly in the second column.
What if the blocks only need to be stacked?
Use gathered when the upper and lower groups need their own local alignments. This is an application of the guide’s documented compact building blocks: each aligned group becomes one row of the containing gathered structure. See amsmath alignment building blocks.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Let \(n\) be an integer and \(a,b\) be scalars.
\begin{equation}
\begin{gathered}
\begin{aligned}
S(n) &= a\bigl[(-1)^n+1-(-1)^n\bigr] \\
&= a(-1)^n+a\bigl(1-(-1)^n\bigr)
\end{aligned} \\
S(n)=\begin{cases}
a+0, & \text{if } n \text{ is even}, \\
-a+2a, & \text{if } n \text{ is odd}
\end{cases} \\
\begin{aligned}
S(n) &= a, \\
S(n)+b &= a+b.
\end{aligned}
\end{gathered}
\end{equation}
\end{document}
This arrangement deliberately gives the top group, middle expression, and bottom group separate horizontal positioning. Their equals signs need not coincide across groups. Repeating S(n) makes the connection explicit, while the last row adds a consequence of the result.
If you need one continuous column of equals signs, return to the first example. Separate aligned groups cannot share an alignment point merely because they appear in the same equation.
How do you diagnose common layout problems?
Work from the outside inward. Identify the numbered display, then the structure that creates its rows, then the cases block. Use this diagnostic sequence before adding spacing adjustments:
- The lower steps appear beside the cases block: check for the outer
\\immediately after\end{cases}. - A supposed continuation appears under the brace: check whether
\end{cases}occurs before that continuation. - The upper and lower equals signs differ: check whether they belong to separate
alignedgroups. Use one outeralignedfor shared alignment. - The document reports erroneous nesting: check for
aligninsideequation. Use the subordinatealignedenvironment in that position. - The fractions look too small: consider
dcasesand loadmathtools.
The nesting diagnostic is supported by the package’s documented recovery for incorrectly nested equation structures, which substitutes aligned; see the amsmath package documentation. The fraction alternative follows the mathtools cases documentation.
For modest extra space after the cases block, replace its outer row ending with \end{cases} \\[4pt]. The amount is an illustrative starting point. Also keep blank lines out of the math environment and omit a row-ending \\ after the final row. These conventions are covered in sections 3.1 and 3.9 of the amsmath user guide.
A substantial limitation is pagination: aligned and gathered form unbreakable structures, so \allowdisplaybreaks will not split them across pages. For an unusually long derivation, restructure the display rather than expecting that command to divide this nested layout. The boundary is documented in amsmath’s guidance on page breaks.
For the ordinary short derivation, start with one equation, one aligned, and a nested cases row. Keep the outer line break after the cases block, verify every branch condition, and switch to a different structure only when you need different horizontal alignment or mathematical sizing.
Sources
- User’s Guide for the amsmath Package — American Mathematical Society and The LaTeX Project.
- The amsmath package — The LaTeX Project, distributed through CTAN.
- The mathtools package — Morten Høgholm, Lars Madsen, and The LaTeX3 Project, distributed through CTAN.
- About TeXShop — Richard Koch, University of Oregon.
- TeXShop Changes — Richard Koch, University of Oregon.