12

I have an equation that I'm trying to display with horizontal line separation. The result I'm looking for is similar to this question, but I'm not sure how to apply it to my equation (below).

\begin{equation*}
\begin{aligned}
x + 3& = &7\\
-3 & = &-3\\
x& = &4\\
\end{aligned}
\end{equation*}

Thanks!

David Carlisle
  • 757,742

2 Answers2

10

It's quite easy, actually: aligned is a special form of array, so \hline works. But I suggest to load the package booktabs:

\usepackage{booktabs}

...

\begin{equation*}
\begin{aligned}
x + 3& = 7\\
\midrule
-3 & = -3\\
\midrule
x& = 4\\
\end{aligned}
\end{equation*}

\midrule produce better spacing than \hline.

aligned (like align) requires a & before the alignment point (usually a relation), but not after it.

As Herbert points out, the vertical spacing may be not optimal. In case this is a real problem, one can resort to array (this requires the array package):

\begin{equation*}
\setlength{\arraycolsep}{0pt}
\begin{array}{r>{{}}l}
x + 3& =  7 \\
\midrule
-3   & = -3 \\
\midrule
x    & = 4
\end{array}
\end{equation*}

The intercolumn space is reduced to zero and before the relation symbol we put an empty group, so that TeX finds {}=7 in the cell, that produces the correct horizontal spacing.

David Carlisle
  • 757,742
egreg
  • 1,121,712
0
\documentclass{article}
\usepackage{booktabs}
\begin{document}

\[\renewcommand\arraystretch{1.4}
  \arraycolsep=1.4pt
\begin{array}{rl}\toprule[1pt]
x + 3& = 7     \\\midrule
-3 & = -3      \\\midrule
x& = 4         \\\bottomrule[1pt]
\end{array}
\]
\end{document}