How to subtract two equations?

This does not look very good but seems close to what your code is attempting to do, where I use \cline{} to draw the horizontal line, and \phantom{y=} to push the minus sign to the left

enter image description here


Recomended Solution:

However, I would suggest the use of \intertext or \shortintertext from the mathtools package, and refer to the equations:

enter image description here

Notes:

  • Requires two runs: first run will display a (??) in the cross reference.
  • \shortintertext yields better spacing but requires an additional package. Alternatively, you can use \intertext which is available in amsmath.
  • The mathtools package already includes amsmath.

Code:

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

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{align}
    y&=2x+5 \label{eqn:one}\\
    y&=3x+10 \label{eqn:two}\\
  \shortintertext{Subtracting \eqref{eqn:two} from \eqref{eqn:one} yields}
    0&=-x-5  \notag
\end{align}
\end{document}

My two-cents worth, using more of a textual representation and an array:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\[
  \begin{array}{l@{\quad}cr@{}l}
    && y & {}= 2x+5 \\
    \text{minus} && y & {}= 3x+10 \\ \cline{2-4}
    && 0 & {}= -x-5
  \end{array}
\]
\end{document}​

The additional (second) column is to allow for the \cline to have a little padding around the equations. Modify \quad to \hspace{<len>} to have a gap of length <len> between "minus" and the equation.


Here is my solution: enter image description here

\documentclass[]{article}

\usepackage{amsmath}
\begin{document}
\begin{alignat*}{4}
    &y&=&&2x&&+&5\\   
    -\hspace*{.5em}&y&=&&3x&&+&10\\[-2.5ex]\cline{2-8}\\[-4.8ex]
    &0&=&&-x&&-&5    
\end{alignat*}

\end{document}

I use the alignat enviroment from amsmath