# How to do right alignment with MathJax?

I want something like

5 + 4 + 3 + 2 + 1
4 + 3 + 2 + 1
…
1


How to do it with MathJax?

A method using AMS math environments:

\begin{align} 5+4+3+2+1&\\ 4+3+2+1&\\ \vdots&\\ 1& \end{align}


\begin{align} 5+4+3+2+1&\\ 4+3+2+1&\\ \vdots&\\ 1& \end{align}

Multicolumn:

\begin{align} 5+4+3+2+1&&5+4+3+2+1\\ 4+3+2+1&&4+3+2+1\\ \vdots&&\vdots\\ 1&&1 \end{align}


\begin{align} 5+4+3+2+1&&5+4+3+2+1\\ 4+3+2+1&&4+3+2+1\\ \vdots&&\vdots\\ 1&&1 \end{align}

Remark:

1. MathJax does not differentiate align and align*.
2. MathJax automatically identifies \begin{...}...\end{...} as math environments, so there is no need to enclose them with $$...$$.
3. Details of math environments are in AMS doc.
• +1 especially for the remarks. May 30 at 2:11

I just found that aligned is right-aligned by default. So it could simply be done like this:

\begin{aligned} 5+4+3+2+1\\ 4+3+2+1\\ \vdots\\ 1 \end{aligned}


Result: \begin{aligned} 5+4+3+2+1\\ 4+3+2+1\\ \vdots\\ 1 \end{aligned}

You can do it as follows:

$$\begin{array}{ccccccccc}5&+&4&+&3&+&2&+&1\\ &&4&+&3&+&2&+&1\\ &&&&&&&&\vdots\\ &&&&&&&&1\end{array}$$

You will get:$$\begin{array}{ccccccccc}5&+&4&+&3&+&2&+&1\\ &&4&+&3&+&2&+&1\\ &&&&&&&&\vdots\\ &&&&&&&&1\end{array}$$

• +1 easy to follow and looks elegant. May 29 at 17:31
• That seems overly complicated. If the goal is to right-align, why not just use a single right-aligned column? e.g. $$\begin{array}{r}5+4+3+2+1\\4+3+2+1\\\end{array}$$ $$\begin{array}{r}5+4+3+2+1\\4+3+2+1\\\end{array}$$
– Xander Henderson Mod
May 29 at 19:50
• @XanderHenderson Yes, that's simpler. May 29 at 19:51
• @XanderHenderson but it's not as spaced as it is in José's answer :p May 30 at 1:08
• After reading all in this post: I concluded.. $\phantom{\begin{array}{}5&+&4&+&3&+&2&+&1\\&&4&+&3&+&2&+&1\\&&&&&&&& \vdots\\&&&&&&&&1 \end{array}}$ May 30 at 5:19
• @VerónicaRmz. I consider the tighter spacing to be a feature, not a bug.
– Xander Henderson Mod
May 30 at 18:38
• @XanderHenderson of course it's not a bug, I'm just saying that I prefer the visualization of the spacing. May 30 at 19:36

Another implementation is by semi-manually adding the correct space with \phantom, which could be useful if it appears inside more complicated objects: \begin{align} 15 &=5+4+3+2+1\\ -5+15 &=\phantom{5+{}}4+3+2+1\\ -4-5+15 &=\phantom{5+4+{}}3+2+1\\ -3-4-5+15 &=\phantom{5+4+3+{}}2+1\\ -2-3-4-5+15 &=\phantom{5+4+3+2+{}}1\\ \end{align}

code (without things on the left of the $$=$$ sign)

\begin{align} &=5+4+3+2+1\\ &=\phantom{5+{}}4+3+2+1\\ &=\phantom{5+4+{}}3+2+1\\ &=\phantom{5+4+3+{}}2+1\\ &=\phantom{5+4+3+2+{}}1\\ \end{align}


NB the {}s are needed so that + gives the spacing of a binary operator.