3
$\begingroup$

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}$$
$\endgroup$
10
$\begingroup$

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

$\endgroup$
4
  • 1
    $\begingroup$ 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$. $\endgroup$
    – amWhy
    Feb 2 at 20:09
  • $\begingroup$ @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). $\endgroup$ Feb 2 at 23:02
  • $\begingroup$ Yes! Thanks for the links, @Jean-ClaudeArbaut ! $\endgroup$
    – amWhy
    Feb 3 at 2:04
  • $\begingroup$ 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. $\endgroup$
    – Good Boy
    Feb 3 at 10:41

You must log in to answer this question.

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