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 would like the elements in my math environment to be left aligned, so that each element stands over each other, like in the given example below. I have managed it using \hspace and \qquad, but thought there is a more elegant way to do this. Can anyone suggest a better solution?

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}
&\gamma(0)=\quad\alpha_1\gamma(1)\hspace{27pt}+\quad\alpha_2\gamma(2)\hspace{27pt}+\quad\dots\quad+\quad\alpha_p\gamma(p)\quad+\quad\sigma^2 \\
&\gamma(1)=\quad\alpha_1\gamma(0)\hspace{27pt}+\quad\alpha_2\gamma(1)\hspace{27pt}+\quad\dots\quad+\quad\alpha_p\gamma(p-1) \\
&\vdots \\
&\gamma(p)=\quad\alpha_1\gamma(p-1)\quad+\quad\alpha_2\gamma(p-2)\quad+\quad\dots\quad+\quad\alpha_p\gamma(0)

\end{aligned}
\end{equation}
\end{document}
share|improve this question
    
Wasn't my answer good enough? :( –  Svend Tveskæg Feb 11 at 10:44
    
I think you adapted your answer to that by Thorsten Donig, didn't you? So I suggest his war slightly better. –  RStudent Feb 11 at 10:51
    
No. I just moved some curly brackets in order to remove the ampersands. I have a feeling that Thorsten took my code and used it. (At least all of his code--minus the ampersands--in the aligned environment is exactly the same as mine, and I posted mine first.) P.S. I haven't got any problem with Thorsten's answer at all. –  Svend Tveskæg Feb 11 at 10:59
    
Are you sure he copied your code? –  RStudent Feb 11 at 12:14
    
No. As I said, I think he did. –  Svend Tveskæg Feb 11 at 12:16

5 Answers 5

up vote 7 down vote accepted

If you want to keep one single equation number, you can use the alignedat environment inside equation.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}  % loads »amsmath«

\pagestyle{empty}
\begin{document}
  \begin{equation}
    \begin{alignedat}{5}
      \gamma(0) &= \alpha_1\gamma(1) &&+ \alpha_2\gamma(2) &&+ \cdots &&+ \alpha_p\gamma(p)&&+ \sigma^2 \\
      \gamma(1) &= \alpha_1\gamma(0) &&+ \alpha_2\gamma(1) &&+ \cdots &&+ \alpha_p\gamma(p-1) \\
      &\vdotswithin{=} \\
      \gamma(p) &= \alpha_1\gamma(p-1)&&+ \alpha_2\gamma(p-2) &&+ \cdots &&+\alpha_p\gamma(0)
    \end{alignedat}
  \end{equation}
\end{document}

enter image description here

share|improve this answer
    
Why load fontenc? –  Svend Tveskæg Feb 10 at 16:52
    
Probably, but the other answer was posted earlier. Unfortunately cannot accept two answers but upvote... –  RStudent Feb 10 at 16:55
    
@SvendTveskæg: I simply always load it. Just a habit when writing in another language than English and for better font quality. Not mandatory here. –  Thorsten Donig Feb 10 at 17:06

Here is a possible solution:

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\begin{alignat*}{5}
  \gamma(0) &= \alpha_1\gamma(1)   &&+ \alpha_2\gamma(2)   &&+ \cdots &&+ \alpha_p\gamma(p)  &&+ \sigma^2 \\
  \gamma(1) &= \alpha_1\gamma(0)   &&+ \alpha_2\gamma(1)   &&+ \cdots &&+ \alpha_p\gamma(p-1)&& \\
            &\vdotswithin{=} \\
  \gamma(p) &= \alpha_1\gamma(p-1) &&+ \alpha_2\gamma(p-2) &&+ \cdots &&+ \alpha_p\gamma(0)  &&
\end{alignat*}

\end{document}

output

share|improve this answer

The accepted answer is definitely the way to go, but if ever you're stuck on a desert island and you don't have the amsmath package, an array environment can do some of the work- there are deficiencies (such as the alignment of the \vdots and the need for extra {}), but it does get some of the job done.

screenshot

% arara: pdflatex
% !arara: indent: {overwrite: on}
\documentclass{article}
\begin{document}
\[
    \begin{array}{r@{}l@{}l@{}l@{}l@{}l@{}l@{}}
        \gamma(0) & {}=\alpha_1\gamma(1)    & {}+\alpha_2\gamma(2)   & {}+{}\cdots {} &   & {}+\alpha_p\gamma(p)   & {}+\sigma^2 \\
        \gamma(1) & {} =\alpha_1\gamma(0)   & {}+\alpha_2\gamma(1)   & {}+{}\cdots {} &   & {}+\alpha_p\gamma(p-1) &             \\
                  & \vdots                  &                        &                &   &                        &             \\
        \gamma(p) & {} =\alpha_1\gamma(p-1) & {}+\alpha_2\gamma(p-2) & {}+{}\cdots {} &   & {}+\alpha_p\gamma(0)   &
    \end{array}
\]
\end{document}
share|improve this answer
    
Looks good, thanks! –  RStudent Feb 10 at 16:36
    
The alignment of the plusses are wrong. Also, the horizontal dots should be \cdots and the \vdots is also aligned wrong. –  Svend Tveskæg Feb 10 at 16:39

This is using the under-development tabstackengine package, first introduced here at Writing a table with equally spaced columns, based on the widest column (source code available at Measuring align).

The package extends the stackengine package by adding tabbing capability. This answer, Can I tab inside of align environment?, gives some of the syntax of the package. I apologize that I have been lax in completing the package and getting it out the door, so the only way to see it in action is by searching this site for tabstackengine.


The spacing between columns is set by \setstacktabbedgap{1em}. The interline spacing by \setstackgap{L}{1.4\baselineskip}.

\documentclass{article}
\usepackage{tabstackengine}
\stackMath
\begin{document}
\begin{equation}
\setstackgap{L}{1.4\baselineskip}
\setstacktabbedgap{1em}
\tabbedCenterstack[l]{%
\gamma(0)&=\alpha_1\gamma(1)&+\alpha_2\gamma(2)&+&\dots&+\alpha_p\gamma(p)&+\sigma^2 \\
\gamma(1)&=\alpha_1\gamma(0)&+\alpha_2\gamma(1)&+&\dots&+\alpha_p\gamma(p-1) \\
\protect\raisebox{-2.5pt}{\vdots} \\
\gamma(p)&=\alpha_1\gamma(p-1)&+\alpha_2\gamma(p-2)&+&\dots&+\alpha_p\gamma(0)
}
\end{equation}
\end{document}

enter image description here

If one wanted the \vdots under the equal sign, at the expense of an additional package (mathtools), the third row of the tabbed stack could be made as

&\protect\raisebox{-2.5pt}{$\protect\vdotswithin{=}$} \\

to achieve a result that looks like

enter image description here

share|improve this answer
    
Your suggestion brings the desired output but I would prefer not using additional package. –  RStudent Feb 10 at 16:41
    
@JohnnyB Understood. It is always a trade-off. I eliminated amsmath from my answer, but you will most likely employ it for your other math needs. –  Steven B. Segletes Feb 10 at 16:42
    
The aligment points and the dots are wrong. –  Svend Tveskæg Feb 10 at 16:43
    
@SvendTveskæg If you mean the \vdots are out of vertical kilter, I see that and have fixed it. What else to you mean by "alignment points"? Do you mean that the ... should be centered between the two plus signs? I fixed that, too. –  Steven B. Segletes Feb 10 at 16:48
    
I think it looked different when I posted the previous comment; now it is only the \vdots. Shouldn't they be aligned under = as in Thorsten's and my answers? –  Svend Tveskæg Feb 10 at 16:54

If you feel brave enough (and have recently read Ch. 22 of the TeXbook) you can always try doing it the plain TeX way.

\documentclass{article}
\begin{document}
\begin{equation}
\vcenter{\openup6pt\halign{\hfil$\gamma(#)={}$&$#$\hfil &&${}+#\hfil$\cr
0 & \alpha_1\gamma(1) & \alpha_2\gamma(2) & \cdots & \alpha_p\gamma(p) & \sigma^2 \cr
1 & \alpha_1\gamma(0) & \alpha_2\gamma(1) & \cdots & \alpha_p\gamma(p-1)\cr
\omit \hfil$\vdots$\enspace\cr
p & \alpha_1\gamma(p-1) & \alpha_2\gamma(p-2) & \cdots & \alpha_p\gamma(0)\cr
}}
\end{equation}
\end{document}

Notice how you can move repeated parts of the display into the preamble, and that you can use \omit to omit the boiler plate where you don't want it. enter image description here

share|improve this answer
    
Really cool solution! –  Svend Tveskæg Feb 11 at 0:23

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.