This is my first topic here in StackExchange. After a lot of research, I couldn't figure out how to align equations to the left and to the right using any environment. For example, I'd like to align this set of three equations:
where all equalities are to be aligned, and also the first two equations, but I want to align them to the right. I mean, I'd like to "shift" the blank space created on the right (after the derivative) to the left of the second line's expression (before the minus sign). I certainly could align them to the right using split environment, but it doesn't allow me to align both the equations and the equal signs.
My code using alignat is written as follows:
\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
\begin{alignat}{3}
(\hat{n}\cdot \nabla \times \hat{n})
&= - \cos^2{(\theta(z))} \cdot \frac{d \theta}{dz} -
\sin^2{(\theta(z))} \cdot \frac{d \theta}{dz} &&= \\
&= - \underbrace{\left[\cos^2{(\theta(z))} + \sin^2{(\theta(z))}
\right]}_{=1} \cdot \frac{d \theta}{dz} &&= \\
&= -\frac{d \theta}{dz}
\end{alignat}
\end{document}
While as using split:
\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
\begin{equation}
\begin{split}
(\hat{n}\cdot \nabla \times \hat{n})
= - \cos^2{(\theta(z))} \cdot \frac{d \theta}{dz} -
\sin^2{(\theta(z))} \cdot \frac{d \theta}{dz}& = \\
= - \underbrace{\left[\cos^2{(\theta(z))} + \sin^2{(\theta(z))}
\right]}_{=1} \cdot \frac{d \theta}{dz}& = \\
= -\frac{d \theta}{dz}
\end{split}
\end{equation}
\end{document}
Where the two first derivatives are aligned to the right, but not the equal signs.
My goal is to do something like this:
I hope I've made myself clear. Thanks in advance.