# Multi horizontal alignment in mathmode

I would like to realize an alignment like the following:

formulaformula1
formulaformulaformula2
formula3
formula4


So I would like formulaformula1 and formulaformulaformula2 to be left aligned, while formula3 and formula4 should be left aligned with a specific position in formulaformulaformula2.

Also I want to frame it with \fbox and put the box in the center.

-

Assuming that you want this in a displaymath format $...$, then you might just as well insert the equation in an array since it allows for easy bordering:

\documentclass{article}
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\lipsum[1]
$\renewcommand{\arraystretch}{1.5}% \begin{array}{|l|} \hline a_0+a_1x+a_2x^2=b_2y^2-b_1y-b_0 \\ c_3z^3\times c_4z^4\times c_5z^5\times c_6z^6\geq a+b+c+d+e \\ \phantom{c_3z^3\times c_4z^4\times{}}c_5z^5-9pq+b\ell\alpha h \\ \phantom{c_3z^3\times c_4z^4\times{}}E=mc^2 \\ \hline \end{array}$
\lipsum[2]
\end{document}


The goal here is to use \phantom{<stuff>} to duplicate <stuff> that you want to use as your alignment tool, but not typeset.

-
• For multi-line formulas with alignment, amsmath environments such as align are useful. For example, alignat* could be used for equations with multiple alignment places. These environments are appropriate for aligning at relation signs such as equal signs, because of consistent spacing around the relation signs.

• For boxing equations, the empheq package is useful. It offers amsmath support and various customizations.

Here's an example:

\documentclass{article}
\usepackage{amsmath}
\usepackage{empheq}
\begin{document}
\begin{empheq}[box=\fbox]{alignat*=2}
&ax + by + c + {}&&x = 0 \\
&ab = c &\\
&&&x+y=z
\end{empheq}
\end{document}


The first two equations are left aligned, the third equation x is aligned with the x in the first equation. Alignment at equal signs is not even used yet.

-
but the spacing of c+x of the first equation is pretty bad. Isn't it a weakness of the alignat environment? –  pluton Aug 20 '11 at 13:04
@pluton: it can be easily fixed by inserting an empty word such as c + {}&&x: so the + gets spacing as a relation sign, I'll edit above. It's not a weakness of alignat. With alignat just be aware of the intention of typesetting in rl columns. –  Stefan Kottwitz Aug 20 '11 at 13:13
What if the width of the second line(ab=c) is larger than the one of the first line? I want them to be left-justified... –  SoftTimur Aug 28 '11 at 3:40