# How to align two or more groups of equations across \items in an enumerated environment?

In the snip, we can see that two groups of equations, aligned individually on the within-group = symbols.

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{enumerate}
\item
\begin{aligned} \int x^2 \cos x \,dx &= x^2 \sin x - 2 \int x \sin x \,dx \\ &= x^2 \sin x - 2 (-x \cos x +\int \cos x \,dx) \\ &= x^2 \sin x - 2 (-x \cos x + \sin x \,dx + C) \\ &= x^2 \sin x + 2x \cos x - 2\sin x + C \end{aligned}

\item
\begin{aligned} \int \frac{\ln x}{x^3} \,dx &= -\frac{1}{2} \frac{\ln x}{x^2} + \frac{1}{2} \int \frac{1}{x^3} \,dx \\ &= -\frac{\ln x}{2x^2} + \frac{1}{2} \cdot -\frac{1}{2x^2} + C \\ &= -\frac{\ln x}{2x^2} - \frac{1}{4x^2} + C \\ &= -\frac{1}{4x^2}(2\ln x + 1) + C \end{aligned}
\end{enumerate}
\end{document}


How to align the two groups of equations on the same equal symbol "="?

Like this:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{enumerate}
\item
\begin{aligned} \int x^2 \cos x \,dx &= x^2 \sin x - 2 \int x \sin x \,dx \\ &= x^2 \sin x - 2 (-x \cos x +\int \cos x \,dx) \\ &= x^2 \sin x - 2 (-x \cos x + \sin x \,dx + C) \\ &= x^2 \sin x + 2x \cos x - 2\sin x + C \\ \\ \int \frac{\ln x}{x^3} \,dx &= -\frac{1}{2} \frac{\ln x}{x^2} + \frac{1}{2} \int \frac{1}{x^3} \,dx \\ &= -\frac{\ln x}{2x^2} + \frac{1}{2} \cdot -\frac{1}{2x^2} + C \\ &= -\frac{\ln x}{2x^2} - \frac{1}{4x^2} + C \\ &= -\frac{1}{4x^2}(2\ln x + 1) + C \end{aligned}
\end{enumerate}
\end{document}


In this approach, the numbers generated by enumerate are missing, so I'm wondering are there better ways.

• Unrelated to your question: you shouldn't use the TeX construct $$...$$ for displayed equations with LaTeX. Use the LaTeX construct $...$ instead, for a correct vertical spacing. Apr 8, 2020 at 15:29
• The use of \intertext looks promising, as in this answer: Aligning equations, splitted in an enumeration Apr 8, 2020 at 15:42
• @barbara Thank you, that's exactly what I'm looking for! I flagged myself duplicate. Apr 8, 2020 at 15:48
• @GeorgeGaarder - Your present query is not a duplicate of the earlier posting. The new and interesting aspect of your query is that the intermediate \item instructions (encased in \intertext or \shortintertext instructions) don't have any visible material associated with them.
– Mico
Apr 8, 2020 at 15:50

I suggest you (a) use a single align* environment across all items and (b) use \intertext instructions in which you execute \item \phantom{x}. (The \phantom{x} directive -- or something similarly invisible -- helps make LaTeX believe that there's actually some material associated with the \item.)

\documentclass{article}
\usepackage{mathtools}
\allowdisplaybreaks
\begin{document}

\begin{enumerate}
\item
\begin{align*}
\int x^2 \cos x \,dx
&= x^2 \sin x - 2 \int x \sin x \,dx \\
&= x^2 \sin x - 2 (-x \cos x +\int \cos x \,dx) \\
&= x^2 \sin x - 2 (-x \cos x + \sin x \,dx + C) \\
&= x^2 \sin x + 2x \cos x - 2\sin x + C \\
\intertext{\refstepcounter{enumi}\labelenumi}
\int \frac{\ln x}{x^3} \,dx
&= -\frac{1}{2} \frac{\ln x}{x^2} +
\frac{1}{2} \int \frac{1}{x^3} \,dx \\
&= -\frac{\ln x}{2x^2} +
\frac{1}{2} \cdot -\frac{1}{2x^2} + C \\
&=  -\frac{\ln x}{2x^2} - \frac{1}{4x^2} + C \\
&= -\frac{1}{4x^2}(2\ln x + 1) + C
\end{align*}
\end{enumerate}

\end{document}

• It's sometimes nice to not have a "blank line" for the item line. I'm not sure this is helpful to accomplish that, but thought I'd mention it: Equations inside enumerate aligned on item's number Apr 8, 2020 at 16:01
• @barbarabeeton - A good suggestion! (I geared my answer to the OP's stated goal of having the item lines blank. It's good to point out other layouts.)
– Mico
Apr 8, 2020 at 16:14