# Underline aligned math addition [duplicate]

I have found several answers to this question. But the answer often lead to modification codes. I wonder if there is simple package for this. I want to align equations and underline or draw a line that makes additions beautiful. There should be simple steps and packages for this.

## marked as duplicate by Werner, user13907, Rico, Martin Schröder, yo'Jan 6 '16 at 18:51

• Your question leaves all the effort to our community, even typing the essentials of a TeX document such as \documentclass{}...\begin{document} etc. As it is, most of our users will be very reluctant to touch your question, and you are left to the mercy of our procrastination team who are very few in number and very picky about selecting questions. You can improve your question by adding a minimal working example (MWE) that more users can copy/paste onto their systems to work on. If no hero takes the challenge we might have to close your question. – Martin Schröder Jan 6 '16 at 18:10

The array environment is like tabular for math. Personally, I would have not included the $a=4$ step in the array with the rest since it doesn't really preserve column integrity.

Note that the = signs are automatically inserted (to get the spacing right).

\documentclass{standalone}

\begin{document}
\setlength{\arraycolsep}{1pt}
$\displaystyle% standalone doesn't support  \begin{array}{c@{\hspace{5pt}}rcr@{{}={}}r} & a & - & b & 3\\ + & a & + & b & 5\\ \hline & 2a & & & 8\\ & & & a & 4 \end{array}$

\end{document}


• +1 looks better than mine, would change the alignment for non-operators to r though ;) – Rico Jan 6 '16 at 16:07
• the spacing around the equal signs looks a bit tight. – barbara beeton Jan 6 '16 at 16:48
• @barbara beeton - Adjusted, but I'm not going to sweat anything less than 1pt off. – John Kormylo Jan 6 '16 at 17:13
• the reason for the comment was that, if there is another expression nearby that is not in an array, say just $x = y$, the difference in spacing around the equal signs would be distracting; same reason that the spacing in eqnarray is so horrid. – barbara beeton Jan 6 '16 at 17:16

You could use the align*

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
a-b&=3\\
{}+a+b&=5\\
\cline{1-2}
2a\phantom{{}+a}&=8\\
a&=4\\
\end{align*}
\end{document}


Which gives you the following

Note the use of \phantom{+a} which I used to move the 2a.

To get better spacing result the tabu package could be interessting. This environment is able to detect if it is in math-mode. You have to use a lot of columns to get a somehow pretty result, though.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tabu}
\begin{document}
$$\begin{tabu}{crcrcr} &a&-&b&=&3\\ +& a&+&b&=&5\\ \cline{2-6} &2a&&&=&8\\ &&&a&=&4\\ \end{tabu}$$
\end{document}


• the spacing would be a bit better with \phantom{{}+a}, and also an empty group {} before the initial plus in the align* version to get the correct spacing there. – barbara beeton Jan 6 '16 at 16:47
• Align* is the most simple but it does get too large vspace from line to equations... – Panha Jan 7 '16 at 0:42
• To reduce this you can have a look at this answer: Remove vertical space around align – Rico Jan 7 '16 at 7:17

Here's an attempt with alignedat from amsmath: Unfortunately had to add the spaces around all the + and - operators

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\begin{alignedat}{3}
&&  a & \,-\, & b &= 3 \\
+\,&&  a & \,+\, & b &= 5 \\
\hline
&& 2a &       &   &= 8 \\
&&    &       & a &= 4
\end{alignedat}
\end{equation*}
\end{document}


• ...or use \mathbin{-}/\mathbin{+}, or {}-{}/{}+{}. – Werner Jan 6 '16 at 18:24
• @Werner mathbin didn't work, {}+{}` did – Steve Jan 6 '16 at 18:28