Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to subtract one equation from another but I can't get it to display the way that I want. This is what I have right now.

\begin{align*}
&y&=2x+5\\   
-&&\\    
&y&=3x+10\\\hline   
&0&=-x-5    
\end{align*}
share|improve this question
6  
Well, how do you want it to display? –  Ryan Reich Feb 1 '12 at 19:22
    
Is this to demonstrate solving linear equations by addition? If so, why not multiply the bottom equation by -1 and present it as addition as you have it: (a la purplemath.com/modules/systlin5.htm). –  badroit Feb 1 '12 at 19:26
    
It looks like this began life as an eqnarray. Try loosing the second & on each line just to start with. –  qubyte Feb 1 '12 at 19:27

5 Answers 5

up vote 16 down vote accepted

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}
share|improve this answer
    
+1 for the recommended version :-) –  Tobi Feb 1 '12 at 21:59
1  
The recommended version is indeed much better in my opinion. A small nitpick: \eqref might be better to make a distinction between numbers and equations. –  percusse Feb 1 '12 at 22:07
    
Seeing your recommended version, I think that it is a better approach. –  russjohnson09 Feb 1 '12 at 23:36
    
@percusse: Thanks for pointing that out. Have updated the solution to correct that. –  Peter Grill Feb 2 '12 at 0:34

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.

share|improve this answer

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

share|improve this answer
1  
Good one. Your spacing around the = on the second line is wrong. try removing the first & on each line. Hmmmm, on second thought, the location of the minus sign means "negative y", not minus the entire equation... –  Peter Grill Feb 1 '12 at 20:03
    
I already noted the problem. and posted the corrected version. thx ;) –  someonr Feb 1 '12 at 20:05
1  
Actually you should just use a single & to get the proper math spacing. Still there is a problem with the meaning of "minus y", which is not the OP's intent. –  Peter Grill Feb 1 '12 at 20:07
    
Yeah ok. I fixed it... But I'm not sure what russjohnson09 would like to see –  someonr Feb 1 '12 at 20:20

Stealing the idea with \frac from this answer but replacing the matrix with aligned. Is it a cute idea? I hope so!

\documentclass[preview,border=12pt,varwidth]{standalone}

\usepackage{amsmath}
\begin{document}
\abovedisplayskip=0pt\relax
\[
    \frac
    {
        \!\begin{aligned} 
                y &=    2x+5\\ 
                y   &=  3x+10 
        \end{aligned}
    }
    {0=-x-5}
    \ -
\]
\end{document}

enter image description here

share|improve this answer

I write it like this:

\[\frac{\begin{matrix} y=2x+5\\ y=3x+10 \end{matrix}}{0=-x-5}\ -\]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.