3

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}

4 Answers 4

2

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}
4
  • 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
    Commented May 12, 2014 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
    Commented May 12, 2014 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
    Commented May 12, 2014 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
    Commented May 20, 2014 at 15:09
1

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!

1

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

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .