# How to align single-digit numbers with multi-digit numbers in multi-line equations?

Use array features. Setting the intercolumn spacing to zero and forcing TeX's automatic spacing around binary relations or operations is simple.

In the second example, which I like better, I also added a rule, which you might like.

The twocolumn option is just to get a smaller picture.

\documentclass[twocolumn]{article}
\usepackage{amsmath,array}

\begin{document}

Right alignment
$\setlength{\arraycolsep}{0pt} \renewcommand{\arraystretch}{1.2} \begin{array}{ r *{5}{ >{{}}c<{{}} r} } S &=& 1 &+& 2 &+& \cdots &+& 99 &+& 100 \\ S &=& 100 &+& 99 &+& \cdots &+& 2 &+& 1 \\ 2S &=& 101 &+& 101 &+& \cdots &+& 101 &+& 101 \end{array}$
Center alignment
$\setlength{\arraycolsep}{0pt} \renewcommand{\arraystretch}{1.2} \begin{array}{ r *{5}{ >{{}}c<{{}} c} } S &=& 1 &+& 2 &+& \cdots &+& 99 &+& 100 \\ S &=& 100 &+& 99 &+& \cdots &+& 2 &+& 1 \\ \cline{3-11} 2S &=& 101 &+& 101 &+& \cdots &+& 101 &+& 101 \end{array}$

\end{document}


You can add rows as follows:

\documentclass[twocolumn]{article}
\usepackage{amsmath,array}

\begin{document}

$\setlength{\arraycolsep}{0pt} \renewcommand{\arraystretch}{1.2} \begin{array}{ r *{5}{ >{{}}c<{{}} c} } S &=& 1 &+& 2 &+& \cdots &+& 99 &+& 100 \\ S &=& 100 &+& 99 &+& \cdots &+& 2 &+& 1 \\ 2S &=& 101 &+& 101 &+& \cdots &+& 101 &+& 101 \\ 2S &=& \multicolumn{9}{l}{101\cdot100} \\[1ex] S &=& \multicolumn{9}{l}{\!\dfrac{101\cdot100}{2}} \end{array}$

\end{document}


The only trick, besides \multicolumn, is \! in the last row to countermand the thin space TeX adds in front of the fraction.

This may seem rather "manual" but actually ends up using less markup than forcing the alignment through alignment cells.

\documentclass{article}

\usepackage{amsmath}

\mathcode\:="8000
{\catcode\:\active\gdef:{\phantom{0}}}

\begin{document}

\begin{align*}
S   &= ::1 + ::2 + \cdots + :99 + 100 \\
S   &= 100 + :99 + \cdots + ::2 + ::1 \\
2S  &= 101 + 101 + \cdots + 101 + 101
\end{align*}

\end{document}


Use alignat{5}:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{alignat*}{5}
S  &=   &   1 &+ {}&   2 &+ \cdots +{} &  99 &+ {}& 100 \\
S  &= & 100 &+ {}&  99 &+ \cdots +   &   2 &+ {}&   1 \\
2S &={} & 101 &+ {}& 101 &+ \cdots +   & 101 &+ {}& 101
\end{alignat*}

\end{document}