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. 
Asked
Active
Viewed 4.3k times
4
Panha
- 587
3 Answers
5
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}
John Kormylo
- 79,712
- 3
- 50
- 120
-
+1 looks better than mine, would change the alignment for non-operators to
rthough ;) – Rico Jan 06 '16 at 16:07 -
-
@barbara beeton - Adjusted, but I'm not going to sweat anything less than 1pt off. – John Kormylo Jan 06 '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 ineqnarrayis so horrid. – barbara beeton Jan 06 '16 at 17:16
1
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}
Rico
- 6,097
-
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 06 '16 at 16:47 -
Align* is the most simple but it does get too large vspace from line to equations... – Panha Jan 07 '16 at 00:42
-
To reduce this you can have a look at this answer: Remove vertical space around align – Rico Jan 07 '16 at 07:17
0
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}
Steve
- 281




\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 06 '16 at 18:10