# How to align multiple symbols for a long equation?

\documentclass[11pt]{article}
\usepackage{xfrac, array, tabu, multirow, graphicx, setspace, dcolumn, tikz}
\usepackage[fleqn]{mathtools}
%the argument for d specifies the maximum number of decimal places
\usepackage[ngerman]{babel}
\usepackage[applemac]{inputenc}
\begin{document}
\begin{align}
\bar{x}&=7+(2\times9) + (2\times10) + (4\times11) + (6\times12) + (7\times14)\\
&+(2\times15) + (3\times16) + 17 + 18 + 19\\
\bar{x}&=14
\end{align}
\end{document}


I was looking long and hard for an answer, I believe {alignat*} is capable to do what I want, I just can't figure out how. I want the too long equation to align as follows: 1st and 3rd row the = should be aligned. But I also want the 1st and 2nd row to be aligned where the first + comes in.

You can use an aligned as follows: \documentclass[11pt]{article}

\usepackage[fleqn]{mathtools}
\begin{document}

\begin{align}
\bar{x}&=\!
\begin{aligned}[t]
7&+(2\times9) + (2\times10) + (4\times11) + (6\times12) + (7\times14)\\
&+(2\times15) + (3\times16) + 17 + 18 + 19\\
\end{aligned}\\
\bar{x}&=14
\end{align}

\end{document}


The \hphantom command is what you are looking for:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\noindent Either
\begin{align}
\bar{x} &= 7 + (2\times9) + (2\times10) + (4\times11) + (6\times12) + (7\times14)\notag\\
&\hphantom{{}= 7} + (2\times15) + (3\times16) + 17 + 18 + 19\\
\bar{x} &= 14
\end{align}
or
\begin{align}
\begin{split}
\bar{x} &= 7 + (2\times9) + (2\times10) + (4\times11) + (6\times12) + (7\times14)\\
&\hphantom{{}= 7} + (2\times15) + (3\times16) + 17 + 18 + 19
\end{split}\\
\bar{x} &= 14
\end{align}
is probably what you are looking for.

\end{document} P.S. Remember {} before = to get the correct horizontal spacing.

• \hphantom is in the TeX core AFAIR, it has nothiong to do with mathtools. – daleif Aug 2 '13 at 13:54
• I see; I'll change my comment accordingly. – Svend Tveskæg Aug 2 '13 at 13:54
• Perhaps the first two lines could be wrapped inside a split environment, so the first expression receives just one number instead of the current two numbers (which are odd). – Gonzalo Medina Aug 2 '13 at 14:16
• @GonzaloMedina Yes.... or just use a \notag at the end of the first line. – Svend Tveskæg Aug 2 '13 at 21:47
• @SvendTveskæg there's a difference, though: using split the number will be vertically centered between the two lines. – Gonzalo Medina Aug 2 '13 at 21:51

You may also be interested in the breqn package, which does this automatically and gets the line numbers sorted out too (moving them out the way of long lines, for example).

It generally breaks equations quite well, but it does not play nicely with some other packages: sansmath, for example, because they both hack deep into the internals of the maths system.