# How can you draw a horizontal line inside an align environment?

I need to draw a horizontal line inside an align environment. E.g., in the following MWE, I need that a line separates the third row.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
x &= 1\\
y & = 2 \\
\hline
x + y &= 3
\end{align*}
\end{document}


EDIT I forgot to mention, the line should not be too long to the left (notice the attached image).

here is a solution

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
x &= 1\\
y & = 2 \\
\cline{1-2}
x + y &= 3
\end{align*}
\end{document}

• Could you please give an explanation about what \cline{} is and what its arguments control. Feb 24 at 20:10
• This solution puts a tremendous amount of vertical whitespace around the line. Feb 24 at 20:15
• Feb 25 at 3:50

Not too sophisticated but you could use a simple rule here.

% arara: pdflatex

\documentclass{article}
\usepackage{mathtools}

\begin{document}
\begin{align*}
x &= 1\\
y & = 2 \-\jot] % you may decrease the vertical space here and in the next line as well. \mathclap{\rule{2cm}{0.4pt}}\\ x + y &= 3 \end{align*} \end{document}  • What is the significance of \mathclap{}? Feb 24 at 20:10 • @young_souvlaki it sets the horizontal part of the bounding box to zero. Like this, the rule does not occupy any space in horizontal direction. Mar 3 at 14:17 Here's another \documentclass{scrartcl} \usepackage{mathtools,array} \begin{document} \[ \begin{array}{>{\displaystyle{}}r@{}>{\displaystyle{}}l} x &= 1\\ y & = 2 \\ \hline x + y &= 3 \end{array}
\end{document}


or may be you like the spacing of booktabs more

\documentclass{scrartcl}
\usepackage{mathtools,array,booktabs}
\begin{document}
$\begin{array}{>{\displaystyle{}}r@{}>{\displaystyle{}}l} x &= 1\\ y & = 2 \\ \midrule x + y &= 3 \end{array}$
\end{document}


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.

User Guide for amsmath

# Update [2.27.22]

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


Just for sake of completeness. In plain TeX, we have no problem.

\eqalign{ x &= 1 \cr y &= 2 \cr \noalign{\smallskip\hrule\smallskip} x + y &= 3 }
\bye


gives desired result.