1
$\begingroup$

I want something like

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

How to do it with MathJax?

$\endgroup$
0

4 Answers 4

8
$\begingroup$

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.
$\endgroup$
1
  • $\begingroup$ +1 especially for the remarks. $\endgroup$
    – Paramanand Singh Mod
    May 30, 2021 at 2:11
3
$\begingroup$

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}$$

$\endgroup$
2
$\begingroup$

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}$$

$\endgroup$
7
  • $\begingroup$ +1 easy to follow and looks elegant. $\endgroup$ May 29, 2021 at 17:31
  • 6
    $\begingroup$ 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}$$ $\endgroup$
    – Xander Henderson Mod
    May 29, 2021 at 19:50
  • $\begingroup$ @XanderHenderson Yes, that's simpler. $\endgroup$ May 29, 2021 at 19:51
  • $\begingroup$ @XanderHenderson but it's not as spaced as it is in José's answer :p $\endgroup$ May 30, 2021 at 1:08
  • $\begingroup$ After reading all in this post: I concluded.. $\phantom{\begin{array}{}5&+&4&+&3&+&2&+&1\\&&4&+&3&+&2&+&1\\&&&&&&&& \vdots\\&&&&&&&&1 \end{array}}$ $\endgroup$ May 30, 2021 at 5:19
  • $\begingroup$ @VerónicaRmz. I consider the tighter spacing to be a feature, not a bug. $\endgroup$
    – Xander Henderson Mod
    May 30, 2021 at 18:38
  • $\begingroup$ @XanderHenderson of course it's not a bug, I'm just saying that I prefer the visualization of the spacing. $\endgroup$ May 30, 2021 at 19:36
2
$\begingroup$

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.

$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .