# Equation alignment “with offset”?

With LaTeX, how do I achieve the following aligned equation?

Dashed lines indicate desired alignments. Solid boxes denote some random expressions.

• You can use the aligned environment. Do you have a minimal example? – Bernard Dec 27 '15 at 22:22
• @Bernard, I didn't. Because I had no idea how to do this. But egreg's idea seems promising. – MetroWind Dec 27 '15 at 23:36
• Egreg used aligned. You should take a look at amsmath documentation. Also mathmode is a comprehensive document about every possible layout problems for maths. – Bernard Dec 27 '15 at 23:52

Your mileage may vary, but here's the idea:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{split} & x^2y+xy(x+y)^6 \\ ={}& \!\begin{aligned}[t] xy( & x+x^6+6x^5y+15x^4y^2+20x^3y^3\\ {}+{} & 15x^2y^4+6xy^5+y^6) \end{aligned} \end{split}

\end{document}


• you beat me by 8 seconds ;) – Runar Dec 27 '15 at 22:28
• @runartrollet Maybe it's not the same idea. – egreg Dec 27 '15 at 22:29

Another approach:

\documentclass[11pt]{article}
\usepackage{amsmath}

\begin{document}
\begin{aligned} A&=&2+2&=4\\ B&=&4\cdot2&=8\\ &+4&&=12\\ \end{aligned}
\end{document}