# Vertically aligned addition equation with MathJax?

I'm working on math project and I need to create simple vertical addition or subtraction equations. I read this page Page. I'm using MathJax for this project.

If I'm using integers everything looks ok

\begin{align} 124& \\ \underline{+\quad 53}& \\ 177& \end{align}

but when I add decimals everything moves into wrong places: \begin{align} 12,4& \\ \underline{+\quad 53}& \\ 177& \end{align}

as you can see 5 is not under 2 (answer is incorrect this is just an example)

another example

\begin{align} 124& \\ \underline{+\quad 53.258}& \\ 177& \end{align}

decimals numbers should be on the right.

\begin{align} 124& \\ \underline{+\quad 53.258}& \\ 177& \end{align}


One lazy fix is to use phantoms:

Expanding the decimal expansions lines things up:

\begin{align} 124\phantom{.000}& \\ \underline{+\quad 53.258}& \\ 177\phantom{.000}& \end{align}


\begin{align} 124\phantom{.000}& \\ \underline{+\quad 53.258}& \\ 177\phantom{.000}& \end{align}

A more correct way is to put the & (alignment) to the left of the decimal point on each line, and use \hline:

\begin{align} 124 & \\ +\quad 53 &.258 \\ \hline 177 & \end{align}


giving

\begin{align} 124& \\ +\quad 53 &.258 \\ \hline 177& \end{align}

• Nice. I've been wanting to know how to show long division, e.g., as well. Something like $$27\, \vert \overline{\;54\quad}$$ with the result, 2, above the overlined 4, of 54. Of course it gets even trickier with a, b where $a \not\mid b$. Feb 2 at 20:09
• @amWhy I would also be interested by long division (and square root as well, but it's close). However, it's amazing, I had absolutely no idea that even for this there were so many differences (see this vs this - no need to read french, see the examples - as well as other languages). Feb 2 at 23:02
• Yes! Thanks for the links, @Jean-ClaudeArbaut ! Feb 3 at 2:04
• As for the division, I would try something like : \begin{align} &\phantom{\sqrt{1}}0\\ 256&\sqrt{1729} \end{align} I.e.,: \begin{align} &\phantom{\sqrt{1}}0\\ 256&\sqrt{1729} \end{align}. The spacing is hard to get right; using array {rl} is another possibility, but you may have to add \!s to the right of the & to narrow the gap. Feb 3 at 10:41