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.

In using the align* environment, how can I get specific numbers to align with each other?

In the following example, I want each term of the top sum and the bottom sum to be aligned with each other:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
2S &= 1 &+ 2 &+ 3 &+ \ldots &+ (N-2) &+ (N-1) &+ N \\
&= N &+ (N-1) &+ (N-2) &+ \ldots &+ 3 &+ 2 &+ 1
\end{align*}
\end{document}

Currently, this looks ugly: alignpic

share|improve this question
2  
An array should be better. –  egreg Dec 25 '13 at 17:42
add comment

2 Answers

up vote 6 down vote accepted

A simple array with some tweaks:

\documentclass{article}
\usepackage{amsmath,array}
\begin{document}
\[
\begin{array}{@{}r<{{}}@{}c*{6}{@{}>{{}}c<{{}}@{}c}@{}}
2S = & 1 & + &   2   & + &   3   & + & \cdots & + & (N-2) & + & (N-1) & + & N \\
{} + & N & + & (N-1) & + & (N-2) & + & \cdots & + &   3   & + &   2   & + & 1
\end{array}
\]
\end{document}

enter image description here

If you want to align the numbers to the minus signs, add new columns.

\documentclass{article}
\usepackage{amsmath,array}
\begin{document}
\[
\begin{array}{@{}r<{{}}*{21}{@{}>{{}}c<{{}}}@{}}
2S = & 1 &+&    & 2 &    &+&    & 3 &    &+& \cdots &+& (N & - & 2) &+& (N & - & 1) &+& N \\
{} + & N &+& (N & - & 1) &+& (N & - & 2) &+& \cdots &+&    & 3 &    &+&    & 2 &    &+& 1
\end{array}
\]
\end{document}

enter image description here

I also fixed the math.

share|improve this answer
add comment

Using the under-development tabstackengine, introduced at Writing a table with equally spaced columns, based on the widest column (sty file found at Measuring align), the process is straightforward:

\documentclass{article}
\usepackage{tabstackengine}
\stackMath
\renewcommand\stackalignment{l}
\begin{document}
\tabbedLongstack{%
  2S &= 1 &+ 2 &+ 3 &+ \ldots &+ (N-2) &+ (N-1) &+ N \\
  &= N &+ (N-1) &+ (N-2) &+ \ldots &+ 3 &+ 2 &+ 1}
\end{document}

enter image description here


OR, as the OP requests, a slightly different look:

\documentclass{article}
\usepackage{tabstackengine}
\stackMath
\begin{document}
\tabbedLongstack{%
  2S &=& 1 &+& 2 &+& 3 &+& \ldots &+& (N-2) &+& (N-1) &+& N \\
  &=& N &+& (N-1) &+& (N-2) &+& \ldots &+& 3 &+& 2 &+& 1}
\end{document}

enter image description here

share|improve this answer
    
Might this look better of the 2s were centered relative to the (N-1)s, and similarly for the 3s and the (N_2)s? –  jamaicanworm Dec 25 '13 at 17:59
1  
@jamaicanworm Please see revision. –  Steven B. Segletes Dec 25 '13 at 18:02
add comment

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.