# Alignment in math environment

Consider the following piece of code

\documentclass[twocolumn]{article}

\usepackage{amsmath}

\begin{document}

\begin{align*}
A_i &= B_i + C_i\\
&= D_i + E_i+F_i + G_i + H_i\\
&= I_i + J_i+K_i + L_i\\
&\hspace{5.5em},\;i=1,\dotsc,m
\end{align*}

\end{document}


which produces the following output using pdfLaTeX

I would like to automatically align the final line, i.e., i=1,...,m, exactly as in the previous picture (in this example far right is at H_i), without manually setting an \hspace{xx} each time.

How can I do that?

-

You should use alignat to introduce multiple alignment points:

\documentclass[twocolumn]{article}
\usepackage{amsmath,lipsum}% http://ctan.org/pkg/{amsmath,lipsum}
\begin{document}

\lipsum*[1]
\begin{alignat*}{2}
A_i &= B_i + C_i \\
&= D_i + E_i+F_i + G_i + H_i \\
&= I_i + J_i+K_i + L_i \\
&                           &&i = 1,\dotsc,m
\end{alignat*}
\lipsum*[2]
\end{document}


The above introduces a left-alignment of i=.... To obtain a right-alignment, use \llap{$i = 1,\dotsc,m$}. This introduces a left overlap at the correct alignment position:

%...
\begin{alignat*}{2}
A_i &= B_i + C_i \\
&= D_i + E_i + F_i + G_i + H_i \\
&= I_i + J_i + K_i + L_i \\
&                             &&\llap{$i = 1,\dotsc,m$}
\end{alignat*}
%...


An illustration of the different alignment options using amsmath is given in Herbert's mathmode document. See section 25 align environments (p 43):

-