Proper nested align? Or split in align

alignamsmathsplit

Say I have a short line and a split long line, both of which I wish to left-justify, while also aligning the long line at the equals sign.
The following code…

\documentclass[oneside,a4paper]{article}
\usepackage{amsmath}

\begin{document}
\begin{align*}
    &f(x)=x^2-x-1\\
    &g(x)=\frac{1}{2}-x\\
    \begin{split}
    (f\circ g)&=f(g(x))=f(\frac{1}{2}-x)=(\frac{1}{2}-x)^2-(\frac{1}{2}-x)-1\\
    &= \frac{1}{4}-x+x^2-\frac{1}{2}+x-1
    \end{split}
\end{align*}
\end{document}

Gives the following result…

result equation

The third and fourth line are properly aligned, but they're not left-justified with the first and second, which is what I'm trying to accomplish.

Best Answer

If you need to economize on (vertical) space, I suggest you use two nested aligned environments inside \[ ... \] rather than nest an aligned environment inside an align* environment. I would also argue that replacing all instances of \frac with \tfrac not only economizes on vertical space even more, it also helps establish more of a visual balance between the various quadratic, linear, and constant terms.

enter image description here

A final remark: I can't help but note that using nested aligned environments does not do all that much to enhance appearance. A single aligned environment, with all five rows aligned on the first = symbols per row, would work just as well -- if not even a bit better...

\documentclass[oneside,a4paper]{article}
\usepackage{amsmath} % for 'aligned' environment

\begin{document}
\[
\begin{aligned}
    &f(x)=x^2-x-1\\
    &g(x)=\tfrac{1}{2}-x\\
    &\begin{aligned}
    (f\circ g)(x) &=f(g(x))=f\bigl(\tfrac{1}{2}-x\bigr)=\bigl(\tfrac{1}{2}-x\bigr)^2-\bigl(\tfrac{1}{2}-x\bigr)-1\\
                  &= \tfrac{1}{4}-x+x^2-\tfrac{1}{2}+x-1 \\
                  &= x^2-\tfrac{5}{4}
     \end{aligned}
\end{aligned}
\]
\end{document}