3

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

enter image description here

\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:

enter image description here

\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.

Mico
  • 506,678
Sherry869
  • 194
  • 2
    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. – Bernard Apr 08 '20 at 15:29
  • 1
    The use of \intertext looks promising, as in this answer: Aligning equations, splitted in an enumeration – barbara beeton Apr 08 '20 at 15:42
  • @barbara Thank you, that's exactly what I'm looking for! I flagged myself duplicate. – Sherry869 Apr 08 '20 at 15:48
  • 2
    @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 08 '20 at 15:50

1 Answers1

3

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.)

enter image description here

\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}
Mico
  • 506,678