Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}?

enter image description here

\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{equation}
   \begin{alignedat}{3}
      G&&{}=&\Big[ &&\hspace*{-7mm} a_i\\
      &&&&&\hspace*{-7mm}+ b_i \Big]\\
      &&&+\sum_{i}&&c_i
\end{alignedat}
\end{equation}

\end{document}
share|improve this question

4 Answers 4

up vote 3 down vote accepted

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{equation}
  \begin{aligned}
    G={} & \Big[
    \!
    \begin{aligned}[t]
      & a_i\\
      &+ b_i \Big]
    \end{aligned}
    \\
    &+\sum_{i}c_i
  \end{aligned}
\end{equation}

\end{document}
share|improve this answer
    
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 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 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 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 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!

share|improve this answer

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}

enter image description here

share|improve this answer

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{equation}
   \begin{alignedat}{3}
      G&&{}=&\Big[ &&\hspace*{-7mm} a_i\\
      &&&&&\hspace*{-7mm}+ b_i \Big]\\
      &&&+\sum_{i}&&c_i
\end{alignedat}
\end{equation}
\par MINE:
\begin{equation}
\def\stackalignment{l}\setstackgap{S}{6pt}\TABbinary
  \tabbedShortstack{
    G=& \Big[&a_i\\
      &&+ b_i \Big]\\
    &\rlap{$+\dsum_{i}c_i$}&
  }
\end{equation}
\begin{equation}
\def\stackalignment{l}\setstackgap{L}{1.8\baselineskip}\TABbinary
  \tabbedCenterstack{
    G=& \Big[&a_i\\
      &&+ b_i \Big]\\
    &\rlap{$+\dsum_{i}c_i$}&
  }
\end{equation}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.