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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
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 6101 times
Stefan
LaTeX.org admin
Post Reply