# 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):

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9982703328132629, "perplexity": 8198.157625293014}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-23/segments/1405997873839.53/warc/CC-MAIN-20140722025753-00228-ip-10-33-131-23.ec2.internal.warc.gz"}