Math & ScienceNumbering in nested align(ed) environments

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
voorneveld
Posts: 15
Joined: Mon Sep 07, 2009 11:18 am

Numbering in nested align(ed) environments

Post by voorneveld »

How can I get an equation number for the third line in the following MWE, where I nest align(ed) environments?

Code: Select all

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align}
\text{maximize } & \text{long expression} \\
\text{with } & \begin{aligned}[t]
a & \in A \\
b & \in B
\end{aligned}
\end{align}
\end{document}
Last edited by Stefan Kottwitz on Fri Mar 02, 2012 11:51 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Numbering in nested align(ed) environments

Post by Stefan Kottwitz »

Hi,

in case different alignment in the rows, I would use two separate align environments instead of nesting.

If it should be one environment though, I would choose the alignat environment which allows several alignment points. A long expression could be "made small" regarding alignment or overlapping alignment points, using \rlap or \clap, which produce a box of width 0 and contained text overlapping to the right or to the left.

Here's an example, where I use many alignment points and column separators, actually in 3 columns:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat}{3}
  \text{maximize } &&& \text{\rlap{long expression}} \\
  \text{with } &&&& a & \in A \\
  &&&& b & \in B
\end{alignat}
\end{document}
Also alignat is explained in the amsmath user's guide. In short: the mandatory argument contains the number of alignment columns, and the & mark both alignment points (right and left aligned as in align) and column separation, alternating.
alignat.png
alignat.png (8.06 KiB) Viewed 6036 times
Stefan
LaTeX.org admin
Post Reply