MathJax for integer summation proof

I have this

$$\begin{array}{r} sum &= 1 + 2 + \ldots + (n - 1) + n \\[1ex] + \; sum &= n + (n-1) + \ldots + 2 + 1 \\ \hline 2\,sum &= (n +1) + (n+1) + \ldots + (n+1) + (n+1) \end{array}$$

for displaying the Gauss trick for summing integers proof, but the alignment is not great. Any suggestions on how to improve this?

• You have not aligned the right-hand column. If you align it to the left then it will align to the equals sign. Use \begin{array}{rl}. If you also want to align the plus signs then you can use the array to do this manually, by putting each plus sign and each number in its own cell. – user1729 Feb 11 at 17:49
• (incidentally, I would have used the align environment for what you wrote, rather than array: \begin{align*}sum&=1+2+\ldots+(n-1)+n\\...\\ \hline 2sum&=...\end{align*}. I would use array to align the plus signs, but that may not be good LaTeX practice...) – user1729 Feb 11 at 17:54

$$\begin{array}{rrcccccccccc} &\text{sum}&=&1&+&2&+&\dots&+&(n-1)&+&n\\ +&\text{sum}&=&n&+&(n-1)&+&\dots&+&2&+&1\\ \hline &2\;\text{sum}&=&(n+1)&+&(n+1)&+&\dots&+&(n+1)&+&(n+1) \end{array}$$

$$\begin{array}{rrcccccccccc} &\text{sum}&=&1&+&2&+&\dots&+&(n-1)&+&n\\ +&\text{sum}&=&n&+&(n-1)&+&\dots&+&2&+&1\\ \hline &2\;\text{sum}&=&(n+1)&+&(n+1)&+&\dots&+&(n+1)&+&(n+1) \end{array}$$

• I just guessed this was the place to ask MathJax questions. Am I right? Also, is there a proper SE MathJax tutorial? I'm still confused by the MathJax - LaTeX gap, i.e., an answer found on SE.Tex doesn't always render in MathJax. – 147pm Feb 11 at 20:22
• @147pm I don't recall when & where now, but I have seen a link to MathJax basic tutorial and quick reference several times. As far as I know, this is the "official" basic MathJax tutorial, and I've used its contents to answer most of my SE MathJax questions. – John Omielan Feb 11 at 20:47
• Since you've used it above, what's the syntax to display a block of code? (As opposed to individual lines of code.) – timtfj Feb 11 at 22:13
• – Mike Earnest Feb 11 at 22:16
• @Mike Thanks! It looks as though the button in the editor is easiest. (Though those lists of bullet points in the post could really do with specifying AND or OR between them! At first I thought I was reading a sequence of instructions, not alternative methods.) – timtfj Feb 11 at 22:25