TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following appears in a text (in the context of generalizing Gauss' famous proof): enter image description here

I would like to reproduce this, but I cannot figure out how to get the alignment down. I thought of trying to use alignat but that does not seem to help (or maybe I simply do not know how to use it properly). Also, I would like for the horizontal line to be placed properly, but this is what I have come up with so far which is rather poor:

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

\begin{align*}
S_n &=& a &+& (a+d) &+\cdots+& [a+(n-1)d]\\
S_n &=& [a+(n-1)d] &+& [a+(n-2)d] &+\cdots+& a\\\hline
2S_n &=& [2a+(n-1)d]&+& [2a+(n-1)d &+\cdots+&[2a+(n-1)d]
\end{align*}

\end{document}

which gives enter image description here

Any ideas on how to obtain the first image effectively?

share|improve this question
up vote 12 down vote accepted

You're better using an array (with some tricks):

\documentclass{article}
\usepackage{amsmath,booktabs,array}

\begin{document}

\begin{equation*}
\setlength{\arraycolsep}{0pt}
\begin{array}{ r *{5}{ >{{}}c<{{}} c } }
 S_n &=& a           &+& (a+d)      &+& \cdots &+& [a+(n-1)d]\\
\addlinespace
 S_n &=& [a+(n-1)d]  &+& [a+(n-2)d] &+& \cdots &+& a\\
\addlinespace
\midrule
\addlinespace
2S_n &=& [2a+(n-1)d] &+& [2a+(n-1)d &+& \cdots &+& [2a+(n-1)d]
\end{array}
\end{equation*}

\end{document}

enter image description here

The >{{}}c<{{}} columns ensure correct spacing around the equals and plus signs, together with \arraycolsep set to zero.

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.