I've done a lot of research on this problem and this is the simplest
solution from all that I've seen. While touhami's answer is great, I take issue with the vertical spacing.
In order to use things like \hline
in a math environment, I found you need to be in a an "sub" math environment* like split
, aligned
, etc.. Once so, you can use your code unchanged:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\begin{split}
x &= 1 \\
y &= 2 \\
\hline
x + y &= 3
\end{split}
\end{equation*}
\end{document}
If you want to include the equation number replace the equation*
environment with equation
:
I'm not entirely pleased with the vertical spacing surrounding \hline
. It could be a bit more with some formulas, but \hline \\[-.5ex]
is not respected. Feel free to leave a solution in the comments and I'll incorporate it.
Other options to document might include trying to wrangle \frac{top}{bottom}
to do what you want.
*Fortification of this statement welcome! My latex knowledge is limited.
Helpful resource:
User Guide for amsmath
Update [2.27.22]
I found a clean way to add a bit more space after the \hline
!
\noalign{\smallskip} \hline \noalign{\smallskip}
Which can be stored in a command:
\newcommand{\eqline}{\noalign{\smallskip} \hline \noalign{\smallskip}}
Output:
Updated tex:
\documentclass{article}
\usepackage{amsmath}
\newcommand{\eqline}{\noalign{\smallskip} \hline \noalign{\smallskip}}
\begin{document}
\begin{equation*}
\begin{split}
x &= 1 \\
y &= 2 \\
\eqline{}
x + y &= 3
\end{split}
\end{equation*}
\end{document}