[Tex/LaTex] How to align an equation within a \begin align block

alignalignatequationssubequations

Right now I have a piece of code which generates the following two equations

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{thmtools}       

\setlength\parindent{0pt}
\usepackage[linesnumbered,ruled]{algorithm2e}
\usepackage{hyperref}
\usepackage{caption} 
\usepackage{cleveref}

\begin{document}
\section{Introduction}

\begin{align*}
& x^2 + 1 = 0\\
& x^3 + 2x^2 + x + 1 = x^4 - 4 = 0 
\end{align*}

\end{document}

I would like to instead, display:
enter image description here

What is the easiest way to achieve this? I tried to nest another align block but I have received an error.

Best Answer

You could used the aligned environment for the nested alignment:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\setlength\parindent{0pt}

\begin{document}
\section{Introduction}
Some text before the equations.
\begin{align*}
    & x^2 + 1 = 0\\
    &\begin{aligned}[t]
        x^3 + 2x^2 + x + 1 &= x^4 - 4 \\
        &= 0
    \end{aligned}
\end{align*}
Some text after them.
\end{document}

Here’s the output I get:

Output of the code

Related Question