# How can I get a nice alignment without using \hspace?

I have two pieces of TeX-code producing almost the same (except numbering) results. Both outputs are desired. However, they contain an ugly thorn \hspace*{-7mm}. I need this command as I am trying to get proper alignment for \Big[ and +\sum from the one hand and for a_i and +b_i from another. How can I achieve that output without using that \hspace*{-7mm}?

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{alignat}{3}
G&&{}=&\Big[ && \hspace*{-7mm} a_i \nonumber\\
&&&&&\hspace*{-7mm} + b_i \Big]\nonumber\\
&&&+\sum_{i}&&c_i
\end{alignat}

\begin{alignedat}{3} G&&{}=&\Big[ &&\hspace*{-7mm} a_i\\ &&&&&\hspace*{-7mm}+ b_i \Big]\\ &&&+\sum_{i}&&c_i \end{alignedat}

\end{document}

-

Here is what I'd do

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{align}
G={} & \Big[
\!
\begin{aligned}[t]
& a_i \\
& + b_i \Big]
\end{aligned}
\nonumber\\
&+\sum_{i} c_i
\end{align}

\begin{aligned} G={} & \Big[ \! \begin{aligned}[t] & a_i\\ &+ b_i \Big] \end{aligned} \\ &+\sum_{i}c_i \end{aligned}

\end{document}

-
I have noticed a negative space \! added before inner alligned environment. Tests show that this \! is really necessary command for getting correct spacing. However, I don't understand why TeX adds extra-space before inner alligned environment. – Andriy May 12 '14 at 16:14
I'm not sure if it is an implementation error or what the reason is. I'm sure if you search the archives here you will find an answer – daleif May 12 '14 at 16:17
@Bernard tuned a bit your solution. He placed \Big[ inside inner alligned environment: ...\Big[ & a_i.... Now we can avoid adding the negative space \!. You can correct your answer. – Andriy May 12 '14 at 17:27
@Andriy, actually it is not. This is a result of using =& instead of = {} &. Using =& there is no added space after the =, you do not notice this because of the extra space being added by aligned – daleif May 20 '14 at 15:09

I have also looked at this because I am spending most of my time trying to understand the way alignat works these days! I came up with the following, which looks more or less the same as your output. I did still have to add a \, before the ] but I think it looks OK.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{alignat}{2}
G= & \Big[ && a_i \nonumber \\
&   && +  b_i \, \Big] \nonumber \\
& + && \sum_{i}c_i
\end{alignat}

\end{document}


I am surprised something seemingly so simple seems so hard to get right!

-

My solution is very similar, but I propose in supplement another alignment point, that looks better in my opinion:

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{amsmath}

\begin{document}

\begin{gather}
\begin{aligned}
G =  &  \begin{aligned}[t]
\Big[&a_i{} \\%
&+ b_i  \Big]
\end{aligned} \\
& +\sum_{i} c_i
\end{aligned} \\[\baselineskip]
\begin{aligned}
G =  &  \begin{aligned}[t]
\Big[a_i&{} \\%
&+ b_i  \Big]
\end{aligned} \\
& +\sum_{i} c_i
\end{aligned}
\end{gather}

\end{document}


-

After giving your two results, I propose TABstacks as the alternative.

\documentclass{article}
\usepackage{tabstackengine, amsmath}
\def\dsum{\displaystyle\sum}
\stackMath
\begin{document}
YOURS:
\begin{alignat}{3}
G&&{}=&\Big[ && \hspace*{-7mm} a_i \nonumber\\
&&&&&\hspace*{-7mm} + b_i \Big]\nonumber\\
&&&+\sum_{i}&&c_i
\end{alignat}
\begin{alignedat}{3} G&&{}=&\Big[ &&\hspace*{-7mm} a_i\\ &&&&&\hspace*{-7mm}+ b_i \Big]\\ &&&+\sum_{i}&&c_i \end{alignedat}
\par MINE:
\def\stackalignment{l}\setstackgap{S}{6pt}\TABbinary \tabbedShortstack{ G=& \Big[&a_i\\ &&+ b_i \Big]\\ &\rlap{+\dsum_{i}c_i}& }
\def\stackalignment{l}\setstackgap{L}{1.8\baselineskip}\TABbinary \tabbedCenterstack{ G=& \Big[&a_i\\ &&+ b_i \Big]\\ &\rlap{+\dsum_{i}c_i}& }
\end{document}


-