# Summation Subtraction Formatting

I am trying to stack two summations -- one on top of the other -- to illustarte term cancellation that takes place when subtracting the two sums. I want the summations to align at the first "=" sign, be centered on the page, and also be underlined. Here is as close as I've gotten:

$$\sum_{i=1}^{n}a_i = a_1+a_2+\ldots+a_{n-2}+a_{n-1}+a_n = \left[\frac{n(n+1)}{2}\right]^4$$

$$-\underline{\sum_{i=1}^{n-1}a_i = a_1+a_2+\ldots+a_{n-2}+a_{n-1} = \left[\frac{n(n-1)}{2}\right]^4}$$

$$a_n = \left[\frac{n(n+1)}{2}\right]^4 - \left[\frac{n(n-1)}{2}\right]^4$$


Any ideas???

• Welcome to TeX.SE! We kindly suggest you to show a full minimal working example (MWE). – Cragfelt Dec 17 '17 at 4:44
• Sorry for being pedantic but, technically, these equations are incorrect as you are in effect writing (A=B) - (C=D) and it does't make much sense to subtract two equations like this. I think that what you want to write is A-C = B-D = .... – Andrew Dec 17 '17 at 7:28
• Does any of these answers solve your issue? If yes, please accept the best that meet your requirements by clicking the check mark next to the answer. See: How does accepting an answer work? for more information. – Cragfelt Dec 21 '17 at 11:27

Another variation on the theme; I find that either you add a minus signs in front of each term in the second equation or in front of none. Just one minus sign is incorrect in all respects.

You can instead use words in order to help the reader in understanding what’s going on.

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

\begin{document}

In order to compute $a_n$, subtract the
second equation from the first one:
\begin{equation*}
\begin{gathered}
\begin{alignedat}{2}
\sum_{i=1}^{n}a_i
& = a_1+a_2+\dots+a_{n-2}+a_{n-1}+a_n
&& = \left[\frac{n(n+1)}{2}\right]^4
\\
\sum_{i=1}^{n-1}a_i
& = a_1+a_2+\dots+a_{n-2}+a_{n-1}
&& = \left[\frac{n(n-1)}{2}\right]^4
\end{alignedat}
\\
\midrule
a_n = \left[\frac{n(n+1)}{2}\right]^4
- \left[\frac{n(n-1)}{2}\right]^4
\end{gathered}
\end{equation*}

\end{document}


Note. \dots should be used between alike symbols, in this case +; amsmath will take care of what kind of dots is needed. In case the dots are trailing, use \dotsb (like between binary symbols), \dotsm (like for multiplication), \dotsi (like between integrals), \dotsc (like between punctuation).

A different way to present the same argument.

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

\begin{document}

We have proved that, for every $n$,
\begin{equation*}
\sum_{i=1}^{n}a_i = \left[\frac{n(n+1)}{2}\right]^4.
\end{equation*}
Thus, for $n\ge1$, we can say
\begin{equation*}
\sum_{i=1}^{n-1}a_i = \left[\frac{n(n-1)}{2}\right]^4
\end{equation*}
which has the consequence that
\begin{equation*}
\left[\frac{n(n+1)}{2}\right]^4=
\sum_{i=1}^{n}a_i =
a_n+\sum_{i=1}^{n-1}a_i =
a_n+ \left[\frac{n(n-1)}{2}\right]^4.
\end{equation*}
Hence, by comparing the first and the last terms,
\begin{equation*}
a_n=\left[\frac{n(n+1)}{2}\right]^4-\left[\frac{n(n-1)}{2}\right]^4.
\end{equation*}

\end{document}


Your question is most likely a duplicate of this question.

\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs}
\begin{document}
% from https://tex.stackexchange.com/questions/23014/horizontal-line-separating-steps-in-aligned-equation
\begin{equation*}
\begin{aligned}
\sum_{i=1}^{n}a_i &=
a_1+a_2+\ldots+a_{n-2}+a_{n-1}+a_n =
\left[\frac{n(n+1)}{2}\right]^4\\
-\sum_{i=1}^{n-1}a_i &=
-\left(a_1+a_2+\ldots+a_{n-2}+a_{n-1}\right) =
-\left[\frac{n(n-1)}{2}\right]^4\\
\midrule
a_n &= \left[\frac{n(n+1)}{2}\right]^4 -
\left[\frac{n(n-1)}{2}\right]^4
\end{aligned}
\end{equation*}
\end{document}


• This is at least confusing; I’d add a minus sign also in the right hand side. – egreg Dec 17 '17 at 10:27
• @egreg You're right. Grazie! – user121799 Dec 17 '17 at 11:25

One possibility is to use align* with the amsmath package. This keeps the spacing correct throughout, unlike the spacing created by making an array. You also have the option to number the rows by removing the *. Alignment is maintained using a \phantom command.

The horizontal line here is inserted as a \rule using \intertext. This can be automated using the booktabs package as others have mentioned.

Code is here:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{align*}
\sum_{i=1}^{n}a_i = a_1+a_2+\cdots+a_{n-2}+a_{n-1}+a_n &= \left[\frac{n(n+1)}{2}\right]^4\\
-\sum_{i=1}^{n-1}a_i = a_1+a_2+\cdots+a_{n-2}+a_{n-1}\phantom{{}+a_n} &= \left[\frac{n(n-1)}{2}\right]^4\\
\intertext{\centering\rule{4.6in}{1pt}}
a_n &=\left[\frac{n(n+1)}{2}\right]^4-\left[\frac{n(n-1)}{2}\right]^4
\end{align*}

\end{document}


I suppose \cdots vs. \ldots is a personal preference.

• Just use \dots for dots between alike symbols and amsmath will take care. – egreg Dec 17 '17 at 10:25

I think the idea of this is to align term to term both sums, so one can show subtraction of summations more properly. For this, one can use an array.

By the way, to pursuing math accuracy, I included the needed - sign before all members of the equations in the second line (not only in the first member) and wrapped into parentheses the expanded sum.

\documentclass{article}
\usepackage{amsmath}
\renewcommand{\arraycolsep}{1pt}

\begin{document}

\subsection*{In-line math display}

$\begin{array}{rcrl} \sum_{i=1}^{n}a_i & = & a_1 + a_2 + \cdots + a_{n-2} + a_{n-1} + a_n & = \left[\frac{n(n+1)}{2}\right]^4 \\[2ex] -\sum_{i=1}^{n-1}a_i & = & - (a_1 + a_2 + \cdots + a_{n-2} + a_{n-1})\hphantom{mm} & = -\left[\frac{n(n-1)}{2}\right]^4 \\[2ex]\hline\\[-2ex] & & a_n & = \left[\frac{n(n+1)}{2}\right]^4-\left[\frac{n(n-1)}{2}\right]^4 \end{array}$

\bigskip

\subsection*{Displaymath}
$\begin{array}{rcrl} \displaystyle\sum_{i=1}^{n}a_i & = & a_1 + a_2 + \cdots + a_{n-2} + a_{n-1} + a_n & = \left[\dfrac{n(n+1)}{2}\right]^4 \\[4ex] \displaystyle-\sum_{i=1}^{n-1}a_i & = & -(a_1 + a_2 + \cdots + a_{n-2} + a_{n-1})\hphantom{mm} & = -\left[\dfrac{n(n-1)}{2}\right]^4 \\[4ex]\hline\\[-1ex] & & a_n & = \left[\dfrac{n(n+1)}{2}\right]^4-\left[\dfrac{n(n-1)}{2}\right]^4 \end{array}$

\end{document}


All answers here are LaTeX oriented but I am not able to read, that LaTeX is required from your answer. So, here is plain TeX solution:

In order to compute $a_n$, subtract the
second equation from the first one:
\eqalign{ \sum_{i=1}^n a_i & = a_1+a_2+\cdots+a_{n-2}+a_{n-1}+a_n = \left[n(n+1)\over 2\right]^4 \cr \sum_{i=1}^{n-1}a_i & = a_1+a_2+\cdots+a_{n-2}+a_{n-1}\phantom{{}+a_n}= \left[n(n-1)\over 2\right]^4 \cr \noalign{\medskip\hrule\medskip} a_n & = \left[n(n+1)\over 2\right]^4 - \left[n(n-1)\over 2\right]^4 }

\bye

• \frac is not a plain TeX command. Nor is ConTeXt used, because it doesn't use . – egreg Dec 17 '17 at 13:23
• @egreg \frac can be defined in plain TeX. We cannot see the whole document, so we cannot see this definition. – wipet Dec 17 '17 at 14:00