# align: using aligned within align troubles

I would like the first two pieces in align look as though they are the only two items in the align environment and the rest to align at the equals signs and separated by some space for the different equality.

Right now it compiles looking like:

So the first two I would like to align as such:

and the last equalities I would like to align as

\documentclass{article}
\usepackage{mathtools}
\usepackage{amssymb}
\begin{document}
\begin{alignat*}{2}
\vec{x}_1(t) &=
\begin{pmatrix}
x_1^{(1)}(t)\\
x_2^{(1)}(t)
\end{pmatrix} &&{}=
\begin{pmatrix}
X_1^{(1)}\cos(\omega_1t + \phi_1)\\
r_1X_1^{(1)}\cos(\omega_1t + \phi_1)
\end{pmatrix}\\
\vec{x}_2(t) &=
\begin{pmatrix}
x_1^{(2)}(t)\\
x_2^{(2)}(t)
\end{pmatrix} &&{}=
\begin{pmatrix}
X_1^{(2)}\cos(\omega_2t + \phi_2)\\
r_2X_1^{(2)}\cos(\omega_2t + \phi_2)
\end{pmatrix}\\
r_1 &=
\begin{aligned}
X_1^{(1)} &&{}= \frac{1}{r_2 - r_1}\bigg[(r_2x_1(0) - x_2(0))^2 +
\frac{(-r_2\dot{x}_1(0) + \dot{x}_2(0))^2}{\omega_1^2}\bigg]^{1/2}
\end{aligned}\\
r_2 &=
\begin{aligned}
X_1^{(2)} &&{}= \frac{1}{r_2 - r_1}\bigg[(-r_1x_1(0) + x_2(0))^2 +
\frac{(r_1\dot{x}_1(0) - \dot{x}_2(0))^2}{\omega_2^2}\bigg]^{1/2}
\end{aligned}\\
\phi_1 &=
\begin{aligned}
\arctan\bigg[\frac{-r_2\dot{x}_1(0) + \dot{x}_2(0)}
\phi_2 &&{}= \arctan\bigg[\frac{r_1\dot{x}_1(0) - \dot{x}_2(0)}
{\omega_2^2(-r_1x_1(0) + x_2(0))}\bigg]
\end{aligned}
\end{alignat*}
\end{document}

• ! Undefined control sequence. l.1 \documentcass  – David Carlisle Nov 7 '14 at 19:09
• ! LaTeX Error: Command \arctan already defined. – David Carlisle Nov 7 '14 at 19:10
• @DavidCarlisle corrected. – dustin Nov 7 '14 at 19:12

\documentclass{article}
\usepackage{mathtools}
\usepackage{amssymb}
\begin{document}
\begin{alignat*}{2}
\vec{x}_1(t) &=
\begin{pmatrix}
x_1^{(1)}(t)\\
x_2^{(1)}(t)
\end{pmatrix} =
\mathrlap{\begin{pmatrix}
X_1^{(1)}\cos(\omega_1t + \phi_1)\\
r_1X_1^{(1)}\cos(\omega_1t + \phi_1)
\end{pmatrix}}\\
\vec{x}_2(t) &=
\begin{pmatrix}
x_1^{(2)}(t)\\
x_2^{(2)}(t)
\end{pmatrix} =
\mathrlap{\begin{pmatrix}
X_1^{(2)}\cos(\omega_2t + \phi_2)\\
r_2X_1^{(2)}\cos(\omega_2t + \phi_2)
\end{pmatrix}}\\
r_1 &=
\frac{3k - m\omega_1^2}{2k} &
X_1^{(1)} &= \frac{1}{r_2 - r_1}\bigg[(r_2x_1(0) - x_2(0))^2 +
\frac{(-r_2\dot{x}_1(0) + \dot{x}_2(0))^2}{\omega_1^2}\bigg]^{1/2}
\\
r_2 &=
\frac{3k - m\omega_2^2}{2k} &
X_1^{(2)} &= \frac{1}{r_2 - r_1}\bigg[(-r_1x_1(0) + x_2(0))^2 +
\frac{(r_1\dot{x}_1(0) - \dot{x}_2(0))^2}{\omega_2^2}\bigg]^{1/2}
\\
\phi_1 &=
\arctan\bigg[\frac{-r_2\dot{x}_1(0) + \dot{x}_2(0)}
{\omega_1^2(r_2x_1(0) - x_2(0))}\bigg] &
\phi_2 &= \arctan\bigg[\frac{r_1\dot{x}_1(0) - \dot{x}_2(0)}
{\omega_2^2(-r_1x_1(0) + x_2(0))}\bigg]
\end{alignat*}
\end{document}

• I'd be inclined to leave a tad more space between the two formulas on the last line. a \quad before the \phi should fix that. – barbara beeton Nov 7 '14 at 19:25
• @barbarabeeton yes I thought same after posting the image, but I had to leave the house to collect a boy:-) – David Carlisle Nov 7 '14 at 21:38
• Here's a case where it makes a considerable difference in the output if one writes \arctan\bigg[ or \arctan\biggl[. The former code tells TeX to insert a thinspace (inappropriately, I believe) between arctan and the opening square bracket; this doesn't happen if you write \arctan\biggl[. See tex.stackexchange.com/a/144439/5001 for further examples of why it pays to use \biggl[ and \biggr] instead of \bigg[ and \bigg]. Shameless self-citation alert!! – Mico Nov 7 '14 at 23:12

I don't understand what's supposed to be achieved by the proposed layout and the attendant alignment of various = symbols. Rather than create the impression that various equations are related in ways that are probably not intended, I'd simplify the layout and get by with a single align* environment and use \qquad statements to insert some horizontal whitespace where needed. Observe that it's important to use \biggl[ instead of just \bigg[ following the two \arctan statements; if you omit the l (mathopen) specifiers, LaTeX will insert an inappropriate whitespace.

\documentclass{article}
\usepackage{amsmath} % for "align*" and "pmatrix" environments
\usepackage{newpxtext}             % Palatino text font
\usepackage[euler-digits]{eulervm} % Euler math font
\begin{document}
\begin{align*}
\vec{x}_1(t) &=
\begin{pmatrix}
x_1^{(1)}(t)\\
x_2^{(1)}(t)
\end{pmatrix} =
\begin{pmatrix}
X_1^{(1)}\cos(\omega_1t + \phi_1)\\
r_1X_1^{(1)}\cos(\omega_1t + \phi_1)
\end{pmatrix}\\
\vec{x}_2(t) &=
\begin{pmatrix}
x_1^{(2)}(t)\\
x_2^{(2)}(t)
\end{pmatrix} =
\begin{pmatrix}
X_1^{(2)}\cos(\omega_2t + \phi_2)\\
r_2X_1^{(2)}\cos(\omega_2t + \phi_2)
r_1 &=
X_1^{(1)} = \frac{1}{r_2 - r_1}\biggl[(r_2x_1(0) - x_2(0))^2 +
\frac{(-r_2\dot{x}_1(0) + \dot{x}_2(0))^2}{\omega_1^2}\biggr]^{1/2}\\
r_2 &=