[Tex/LaTex] Vertical alignment of align* in enumerate

#enumeratealignlistsvertical alignment

Related (but not the same):
Align number from enumerate with equation
Displaying an equation in a list

Earlier today I asked a question about aligning equations in an enumerate environment and got an answer that seemed to work for the example I gave, but it turns out I wasn't really specific enough for my problem.

I'm using align* environments, often as the only part of a list item. (If you're wondering why I'm not using more words to introduce the align*, these are mostly homework solutions where most of the work is algebra, etc.)

Here's my code and what it makes (above the middle line):

\begin{enumerate}
  \item \begin{align*}
    x^2 + y^2 &= x^2 + (iy)^2 \\
              &= (x + iy) (x - iy)
  \end{align*}
  \item \begin{align*}
    \frac{1}{n^2-4} &= \frac14 \frac{4}{(n-2)(n+2)} \\
                    &= \frac14 \left( \frac{1}{n-2}-\frac{1}{n+2} \right)
  \end{align*}
\end{enumerate}

sad things

I'm trying to make the baseline of the first line of the align* environment the same as the number's baseline—I want the first line of the align* to have the same vertical position (centered horizontally in the same way) relative to its number as in the second half of my picture. (Side question: why is there so much space before the align* starts?)

Best Answer

I had been using Philippe Goutet's solution posted here, but have fairly recently found a simpler solution of using the aligned environment with the optional [t] alignment:

  \item $\begin{aligned}[t]
    x^2 + y^2 &= x^2 + (iy)^2 \\
              &= (x + iy) (x - iy)
  \end{aligned}$

which yields:

enter image description here

Notes:

Code:

\documentclass{article}
\usepackage{showframe}
\usepackage{amsmath}

\begin{document}
\begin{enumerate}
  \item $\begin{aligned}[t]
    x^2 + y^2 &= x^2 + (iy)^2 \\
              &= (x + iy) (x - iy)
  \end{aligned}$
  \item $\begin{aligned}[t]
    \frac{1}{n^2-4} &= \frac14 \frac{4}{(n-2)(n+2)} \\
                    &= \frac14 \left( \frac{1}{n-2}-\frac{1}{n+2} \right)
  \end{aligned}$
\end{enumerate}
\end{document}

If you want them horizontally centered as is the default with the align environment you could add an \hfill on either side:

  \item \hfill$\begin{aligned}[t]
    x^2 + y^2 &= x^2 + (iy)^2 \\
              &= (x + iy) (x - iy)
  \end{aligned}$\hfill\null

enter image description here

Code:

\documentclass{article}
\usepackage{showframe}
\usepackage{amsmath}

\begin{document}
\begin{enumerate}
  \item \hfill$\begin{aligned}[t]
    x^2 + y^2 &= x^2 + (iy)^2 \\
              &= (x + iy) (x - iy)
  \end{aligned}$\hfill\null
  \item \hfill$\begin{aligned}[t]
    \frac{1}{n^2-4} &= \frac14 \frac{4}{(n-2)(n+2)} \\
                    &= \frac14 \left( \frac{1}{n-2}-\frac{1}{n+2} \right)
  \end{aligned}$\hfill\null
\end{enumerate}
\end{document}