# "Erroneous nesting of equation structures" message- I can't see what's wrong?

I have the following system of equations in Texmaker:

\begin{align} \begin{split} a(t_{n+1}) \cos \varphi_{n+1} = a(t_{n}) \cos \varphi_{n} + \sqrt{2E_{n}}(t_{n+1} - t_{n}) \cos( \alpha_{n}+ \theta{_n}), \\ b(t_{n+1})\sin \varphi_{n+1} \left(1+ \delta \sin^{2} \varphi_{n+1} \right) = b(t_{n})\sin \varphi_{n} \left(1+ \delta \sin^{2} \varphi_{n} \right) + \sqrt{2E_{n}}(t_{n+1}-t_{n}) \sin (\alpha_{n} + \theta_{n}), \\ \theta_{n} + \alpha_{n} + \theta^{*}_{n+1} - \alpha_{n+1} = 0, \\ \sqrt{2E_{n+1}}\cos \theta_{n+1} = \sqrt{2E_{n}}\cos\theta^{*}_{n+1}, \\ \sqrt{2E_{n+1}}\sin\theta_{n+1} = \sqrt{2E_{n}}\sin\theta^{*}_{n+1}-2u(\varphi_{n+1}, t_{n+1}). \end{split} \end{align} \label{system}


When I compile, the following error message is given:"Package amsmath error: Erroneous nesting of equation structures; (amsmath) trying to recover with aligned...." However, I can still produce a normal looking PDF file.

I'd be very grateful if someone could point out how to correct this error. I have the amsmath package installed.

• align is already in math mode, so get rid of the equation environment. Commented May 30, 2017 at 12:25

You should not nest align in equation. The align environment is enough:

\documentclass[]{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
\begin{split}
a(t_{n+1}) \cos \varphi_{n+1} = a(t_{n}) \cos \varphi_{n} + \sqrt{2E_{n}}(t_{n+1} - t_{n}) \cos( \alpha_{n}+ \theta{_n}),
\\
b(t_{n+1})\sin \varphi_{n+1} \left(1+ \delta \sin^{2} \varphi_{n+1} \right) = b(t_{n})\sin \varphi_{n} \left(1+ \delta \sin^{2} \varphi_{n} \right) + \sqrt{2E_{n}}(t_{n+1}-t_{n}) \sin (\alpha_{n} + \theta_{n}),
\\
\theta_{n} + \alpha_{n} + \theta^{*}_{n+1} - \alpha_{n+1} = 0,
\\
\sqrt{2E_{n+1}}\cos \theta_{n+1} = \sqrt{2E_{n}}\cos\theta^{*}_{n+1},
\\
\sqrt{2E_{n+1}}\sin\theta_{n+1} = \sqrt{2E_{n}}\sin\theta^{*}_{n+1}-2u(\varphi_{n+1}, t_{n+1}).
\end{split}
\label{system}
\end{align}
\end{document}


This compiles (but looks terrible, imho).

With horizontal alignment it looks better I think:

\documentclass[]{article}

\usepackage{amsmath}
\usepackage[margin=1cm]{geometry}

\begin{document}
Without alignment:
\begin{align}
\begin{split}
a(t_{n+1}) \cos \varphi_{n+1} = a(t_{n}) \cos \varphi_{n} + \sqrt{2E_{n}}(t_{n+1} - t_{n}) \cos( \alpha_{n}+ \theta{_n}),
\\
b(t_{n+1})\sin \varphi_{n+1} \left(1+ \delta \sin^{2} \varphi_{n+1} \right) = b(t_{n})\sin \varphi_{n} \left(1+ \delta \sin^{2} \varphi_{n} \right) + \sqrt{2E_{n}}(t_{n+1}-t_{n}) \sin (\alpha_{n} + \theta_{n}),
\\
\theta_{n} + \alpha_{n} + \theta^{*}_{n+1} - \alpha_{n+1} = 0,
\\
\sqrt{2E_{n+1}}\cos \theta_{n+1} = \sqrt{2E_{n}}\cos\theta^{*}_{n+1},
\\
\sqrt{2E_{n+1}}\sin\theta_{n+1} = \sqrt{2E_{n}}\sin\theta^{*}_{n+1}-2u(\varphi_{n+1}, t_{n+1}).
\end{split}
\label{system}
\end{align}

With alignment:
\begin{align}
\begin{split}
a(t_{n+1}) \cos \varphi_{n+1} &= a(t_{n}) \cos \varphi_{n} + \sqrt{2E_{n}}(t_{n+1} - t_{n}) \cos( \alpha_{n}+ \theta{_n}),
\\
b(t_{n+1})\sin \varphi_{n+1} \left(1+ \delta \sin^{2} \varphi_{n+1} \right) &= b(t_{n})\sin \varphi_{n} \left(1+ \delta \sin^{2} \varphi_{n} \right) + \sqrt{2E_{n}}(t_{n+1}-t_{n}) \sin (\alpha_{n} + \theta_{n}),
\\
\theta_{n} + \alpha_{n} + \theta^{*}_{n+1} - \alpha_{n+1} &= 0,
\\
\sqrt{2E_{n+1}}\cos \theta_{n+1} &= \sqrt{2E_{n}}\cos\theta^{*}_{n+1},
\\
\sqrt{2E_{n+1}}\sin\theta_{n+1} &= \sqrt{2E_{n}}\sin\theta^{*}_{n+1}-2u(\varphi_{n+1}, t_{n+1}).
\end{split}
\label{system2}
\end{align}
\end{document}


• Thanks! By the way, what would you do to make it look less "terrrible"? @Skillmon
– Alex
Commented May 30, 2017 at 12:31
• @Alex I would add a & to all the = in the split-environment. This way, the = get horizontally aligned, which makes the appearance clearer, imho. Commented May 30, 2017 at 12:32
• What's the usefulness of split nested in align? Commented May 30, 2017 at 12:56
• @Bernard the placement of the equation number in the vertical center. If it's wanted, I think split is really handy (and I just didn't remove it from the question) Commented May 30, 2017 at 13:08
• @Skillmon: Oh! yes. Usually I do that with equation+aligned (or +split), so it seemed strange to me. Commented May 30, 2017 at 13:38

align already puts you in math mode, so get rid of the redundant equation environment. I also moved the \label inside the align.

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{amsmath}
\begin{document}
%\begin{align} \begin{split} a(t_{n+1}) \cos \varphi_{n+1} = a(t_{n}) \cos \varphi_{n} + \sqrt{2E_{n}}(t_{n+1} - t_{n}) \cos( \alpha_{n}+ \theta{_n}), \\ b(t_{n+1})\sin \varphi_{n+1} \left(1+ \delta \sin^{2} \varphi_{n+1} \right) = b(t_{n})\sin \varphi_{n} \left(1+ \delta \sin^{2} \varphi_{n} \right) + \sqrt{2E_{n}}(t_{n+1}-t_{n}) \sin (\alpha_{n} + \theta_{n}), \\ \theta_{n} + \alpha_{n} + \theta^{*}_{n+1} - \alpha_{n+1} = 0, \\ \sqrt{2E_{n+1}}\cos \theta_{n+1} = \sqrt{2E_{n}}\cos\theta^{*}_{n+1}, \\ \sqrt{2E_{n+1}}\sin\theta_{n+1} = \sqrt{2E_{n}}\sin\theta^{*}_{n+1}-2u(\varphi_{n+1}, t_{n+1}). \end{split} \label{system} \end{align} %
\end{document}


Alternately, you can keep the equation environment, and change align to aligned:

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{amsmath}
\begin{document}
\begin{aligned} \begin{split} a(t_{n+1}) \cos \varphi_{n+1} = a(t_{n}) \cos \varphi_{n} + \sqrt{2E_{n}}(t_{n+1} - t_{n}) \cos( \alpha_{n}+ \theta{_n}), \\ b(t_{n+1})\sin \varphi_{n+1} \left(1+ \delta \sin^{2} \varphi_{n+1} \right) = b(t_{n})\sin \varphi_{n} \left(1+ \delta \sin^{2} \varphi_{n} \right) + \sqrt{2E_{n}}(t_{n+1}-t_{n}) \sin (\alpha_{n} + \theta_{n}), \\ \theta_{n} + \alpha_{n} + \theta^{*}_{n+1} - \alpha_{n+1} = 0, \\ \sqrt{2E_{n+1}}\cos \theta_{n+1} = \sqrt{2E_{n}}\cos\theta^{*}_{n+1}, \\ \sqrt{2E_{n+1}}\sin\theta_{n+1} = \sqrt{2E_{n}}\sin\theta^{*}_{n+1}-2u(\varphi_{n+1}, t_{n+1}). \end{split} \label{system} \end{aligned}
\end{document}

• Thank you, this fixed my problem when I had \begin{align}.....\end{align}. Getting rid of the $$allowed it to typeset seamlessly Commented Jun 15, 2021 at 2:41 • @user71207 It is a common enough mistake for beginners to LaTeX. Another is to use $$ at all. That is a construct for TeX, and while LaTeX does not complain of it, you instead, when needed, should use $...$ or the amsmath package \begin{equation*}...\end{equation*} when the equation is not to be numbered, and $$...$$ when it is to be numbered. The various amsmath align-style environments are for when multiple equations reside in the set. Commented Jun 15, 2021 at 8:57

Youn don't have to nest align equation. If you want a single equation number, nest aligned or split, but not both, and use & for the alignment point. I suggest three possible layouts: either with aligned and the second, very long, line split with multlined from mathtools, or with gathered and multlined (no alignment point), or aligned but for the second line:

    \documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{mathtools, nccmath}

\begin{document}

\begin{aligned} a(t_{n+1}) \cos \varphi_{n+1} & = a(t_{n}) \cos \varphi_{n} + \sqrt{2E_{n}}(t_{n+1} - t_{n}) \cos( \alpha_{n}+ \theta_{n}), \\ b(t_{n+1})\sin \varphi_{n+1} \left(1+ \delta \sin^{2} \varphi_{n+1} \right) & = \begin{multlined}[t] b(t_{n})\sin \varphi_{n} \left(1+ \delta \sin^{2} \varphi_{n} \right) \\+ \sqrt{2E_{n}}(t_{n+1}-t_{n}) \sin (\alpha_{n} + \theta_{n}),\end{multlined} \\% \theta_{n} + \alpha_{n} + \theta^{}_{n+1} - \alpha_{n+1} & = 0, \\% \sqrt{2E_{n+1}}\cos \theta_{n+1} & = \sqrt{2E_{n}}\cos\theta^{}_{n+1}, \\% \sqrt{2E_{n+1}}\sin\theta_{n+1} & = \sqrt{2E_{n}}\sin\theta^{*}_{n+1}-2u(\varphi_{n+1}, t_{n+1}). \end{aligned}\label{system}
\bigskip
$$\begin{gathered} a(t_{n+1}) \cos \varphi_{n+1} = a(t_{n}) \cos \varphi_{n} + \sqrt{2E_{n}}(t_{n+1} - t_{n}) \cos( \alpha_{n}+ \theta_{n}), \\ b(t_{n+1})\sin \varphi_{n+1} \left(1+ \delta \sin^{2} \varphi_{n+1} \right) = \begin{multlined}[t] b(t_{n})\sin \varphi_{n} \left(1+ \delta \sin^{2} \varphi_{n} \right) \\+ \sqrt{2E_{n}}(t_{n+1}-t_{n}) \sin (\alpha_{n} + \theta_{n}),\end{multlined} \\% \theta_{n} + \alpha_{n} + \theta^{}_{n+1} - \alpha_{n+1} = 0, \\% \sqrt{2E_{n+1}}\cos \theta_{n+1} = \sqrt{2E_{n}}\cos\theta^{}_{n+1}, \\% \sqrt{2E_{n+1}}\sin\theta_{n+1}= \sqrt{2E_{n}}\sin\theta^{*}_{n+1}-2u(\varphi_{n+1}, t_{n+1}). \end{gathered}\label{system}$$
\bigskip
\begin{aligned} a(t_{n+1}) \cos \varphi_{n+1} & = a(t_{n}) \cos \varphi_{n} + \sqrt{2E_{n}}(t_{n+1} - t_{n}) \cos( \alpha_{n}+ \theta_{n}), \\ % \MoveEqLeft[2]\mathclap{b(t_{n+1})\sin \varphi_{n+1} \left(1+ \delta \sin^{2} \varphi_{n+1} \right) = b(t_{n})\sin \varphi_{n} \left(1+ \delta \sin^{2} \varphi_{n} \right) \mathrlap{+ \sqrt{2E_{n}}(t_{n+1}-t_{n}) \sin (\alpha_{n} + \theta_{n}),}} \\% \theta_{n} + \alpha_{n} + \theta^{}_{n+1} - \alpha_{n+1} & = 0, \\% \sqrt{2E_{n+1}}\cos \theta_{n+1} & = \sqrt{2E_{n}}\cos\theta^{}_{n+1}, \\% \sqrt{2E_{n+1}}\sin\theta_{n+1} & = \sqrt{2E_{n}}\sin\theta^{*}_{n+1}-2u(\varphi_{n+1}, t_{n+1}). \end{aligned}\label{system}

\end{document}