Math & ScienceHow to put a horizontal line in eqnarray

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
twisterrob
Posts: 1
Joined: Sat Jan 17, 2009 9:29 pm

How to put a horizontal line in eqnarray

Post by twisterrob »

In high school we used to solve a system of equation like this:

Code: Select all

x + y = 10
x - y = 5
----------------
x + y = 10
    x = 5 + y
----------------
(5 + y) + y = 10
     5 + 2y = 10
         2y = 5
          y = 2.5
          x = 5 + 2.5 = 7.5
Now I would like to write an equation array like this:

Code: Select all

\begin{eqnarray*}
x + y &=& 10\\
x - y &=& 5\\
\hline % gives compliation error, that \hline command does not exists
x + y &=& 10\\
x &=& 5 + y\\
\hline % gives compliation error, that \hline command does not exists
(5 + y) + y &=& 10\\
5 + 2y &=& 10\\
2y &=& 5\\
y &=& 2.5\\
x &=& 5 + 2.5 = 7.5
\end{eqnarray*}
I would like to know how to do it! What to write instead of \hline? (I know how to do with tables/tabulars (where \hline simply just works), I want to do it without tabular or array env) with eqnarray like enviroment (maybe align?)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How to put a horizontal line in eqnarray

Post by localghost »

At the moment I can only offer an intermediate solution.

Code: Select all

\begin{align*}
  x + y &= 10 \\
  x - y &= 5 \\
  ------&-------- \\
  x + y &= 10 \\
  x &= 5 + y \\
  ------&-------- \\
  (5 + y) + y &= 10 \\
  5 + 2y &= 10 \\
  2y &= 5 \\
  y &= 2.5 \\
  x &= 5 + 2.5 = 7.5
\end{align*}
The horizontal lines are dashed.


Best regards
Thorsten¹
James
Posts: 7
Joined: Tue Jan 13, 2009 12:23 am

How to put a horizontal line in eqnarray

Post by James »

You can use \cline:

Code: Select all

\begin{align*}
  x + y &= 10 \\
  x - y &= 5 \\
  \cline{1-2}
  x + y &= 10 \\
  x &= 5 + y \\
  \cline{1-2}
  (5 + y) + y &= 10 \\
  5 + 2y &= 10 \\
  2y &= 5 \\
  y &= 2.5 \\
  x &= 5 + 2.5 = 7.5
\end{align*}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

How to put a horizontal line in eqnarray

Post by Stefan Kottwitz »

Hi,

don't use eqnarray, see eqnarray vs. align for a short explanation.
You could see the problem already in your example, just look at the spacing around the equal signs of the last line.

Stefan
LaTeX.org admin
Lauren
Posts: 1
Joined: Wed May 06, 2009 11:21 pm

How to put a horizontal line in eqnarray

Post by Lauren »

I am using the \cline workaround suggested above, and have found that a large amount of vertical whitespace is inserted before the horizontal line, so I do this:

Code: Select all

    \begin{align*}
      x + y &= 10 \\
      x - y &= 5 \\[-11pt]
      \cline{1-2}
      x + y &= 10 \\
      x &= 5 + y \\[-11pt]
      \cline{1-2}
      (5 + y) + y &= 10 \\
      5 + 2y &= 10 \\
      2y &= 5 \\
      y &= 2.5 \\
      x &= 5 + 2.5 = 7.5
    \end{align*}
This seems less than optimal, although it works. Does anyone have a better suggestion?
Post Reply