Math & Scienceeqnarray + lines of text?

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Diff Eq
Posts: 7
Joined: Tue Sep 04, 2007 4:09 pm

eqnarray + lines of text?

Post by Diff Eq »

Hi,

I'm just starting to get familiar with LaTeX.

I have a block of text that contains both equations and lines of text. I'd like to have the equations displayed using eqnarray so that the equal signs are aligned and I'd like for them to be numbered. But! I'd also like to have text in between the equations.

For example:

Code: Select all

  [Equation 1]
or in normalized form:
  [Equation 2]
The other approximate solutions are:
  [Equation 3]
or in normalized form:
  [Equation 4]
Keep in mind that I'd like Eq's 1-4 to be aligned with their equal signs (via eqnarray?).

Can anyone help point me in the right direction with figuring this out?

Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Diff Eq
Posts: 7
Joined: Tue Sep 04, 2007 4:09 pm

eqnarray + lines of text?

Post by Diff Eq »

Also, while we're at it, another thing I've been flipping through the help documentation trying to find is being able to have LaTeX follow a custom equation numbering system. Sometimes it's neccessary to have something like the following:

Code: Select all

Equation 1
Equation 2
Equation 2a
Equation 3
Equation 4
Equation 4a
Equation 4b
What's the best way to approach this?

Thanks again!
laurenmalone
Posts: 4
Joined: Tue Aug 28, 2007 4:11 pm

eqnarray + lines of text?

Post by laurenmalone »

Try using the \multline command (I'm pretty sure you have to use \split with \multline)....here you use an ampersand (&) to align (so you would place them in front of the equal signs), and you could play around with how to align your text.

I hope this helps.

Diff Eq wrote: Hi,

I'm just starting to get familiar with LaTeX.

I have a block of text that contains both equations and lines of text. I'd like to have the equations displayed using eqnarray so that the equal signs are aligned and I'd like for them to be numbered. But! I'd also like to have text in between the equations.

For example:

Code: Select all

  [Equation 1]
or in normalized form:
  [Equation 2]
The other approximate solutions are:
  [Equation 3]
or in normalized form:
  [Equation 4]
Keep in mind that I'd like Eq's 1-4 to be aligned with their equal signs (via eqnarray?).

Can anyone help point me in the right direction with figuring this out?

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

eqnarray + lines of text?

Post by localghost »

To solve the problem in your first post, do not use the eqnarray environment any more. The reasons for that can be found in l2tabu-english. Include the package amsmath from the AMS LaTeX Bundle and use the align environment.

Code: Select all

\begin{align}
  (a+b)^2&=a^2+2ab+b^2 \\
  \intertext{Here comes some text between equations}
  (a-b)^2&=a^2-2ab+b^2 \\
  \intertext{with the equations aligned to their equal signs}
  (a+b)(a-b)&=a^2-b^2
\end{align}
Note that "&" is used as alignment character similar to that in the tabular environment.

The problem in your second post is also solved by amsmath. Just take a look at the subequations environment.

Code: Select all

\begin{subequations}\label{eqn:binomi}
  \begin{align}
    (a+b)^2&=a^2+2ab+b^2 \label{subeqn-1:binomi} \\
    (a-b)^2&=a^2-2ab+b^2 \label{subeqn-2:binomi} \\
    (a+b)(a-b)&=a^2-b^2 \label{subeqn-3:binomi}
  \end{align}
\end{subequations}
With the labels set in this way you can refer to the whole group of equations as well as to the single subequations. For further information take a look at the documentation of amsmath.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Diff Eq
Posts: 7
Joined: Tue Sep 04, 2007 4:09 pm

eqnarray + lines of text?

Post by Diff Eq »

Ah! I got it, I think.

Thanks for your help!
localghost wrote: To solve the problem in your first post, do not use the eqnarray environment any more. The reasons for that can be found in l2tabu-english. Include the package amsmath from the AMS LaTeX Bundle and use the align environment.

Code: Select all

\begin{align}
  (a+b)^2&=a^2+2ab+b^2 \\
  \intertext{Here comes some text between equations}
  (a-b)^2&=a^2-2ab+b^2 \\
  \intertext{with the equations aligned to their equal signs}
  (a+b)(a-b)&=a^2-b^2
\end{align}
Note that "&" is used as alignment character similar to that in the tabular environment.

The problem in your second post is also solved by amsmath. Just take a look at the subequations environment.

Code: Select all

\begin{subequations}\label{eqn:binomi}
  \begin{align}
    (a+b)^2&=a^2+2ab+b^2 \label{subeqn-1:binomi} \\
    (a-b)^2&=a^2-2ab+b^2 \label{subeqn-2:binomi} \\
    (a+b)(a-b)&=a^2-b^2 \label{subeqn-3:binomi}
  \end{align}
\end{subequations}
With the labels set in this way you can refer to the whole group of equations as well as to the single subequations. For further information take a look at the documentation of amsmath.
svensandberg
Posts: 2
Joined: Wed Feb 11, 2009 10:59 am

eqnarray + lines of text?

Post by svensandberg »

I have the same problem with a small twist: align doesn't work for me. I use eqnarray because it allows me to have one column aligned centrally, whereas align only seems to allow left- and right justified columns.

Specifically, I want to do the following:

Code: Select all

\begin{eqnarray}
  x &=& y+z \\
  & \stackrel{\text{[by of Lemma A]}}{=} & y+w \\

  \intertext{Now, we can prove the theorem:}

  r & \stackrel{\text{[by Lemma B]}}{=} & x \\
  &=& y+w
\end{eqnarray}
The equality signs are of different widths because of the \stackrel{}{}. Hence the column containing the equality signs must be center aligned in order for the equality signs to line up.

So, is there any way to allow both intertext and center-aligned columns?
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

eqnarray + lines of text?

Post by localghost »

svensandberg wrote:I have the same problem with a small twist: align doesn't work for me. [...]
Please explain this by creating a minimal working example (MWE) that shows what is not working. The only thing you need for the align environment is the amsmath package. A possible solution is provided by phi in another topic [1]. Note also the comment of daleif on this issue.

[1] View topic: Aligning relation symbols in align*


Best regards and welcome to the board
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

eqnarray + lines of text?

Post by daleif »

svensandberg wrote:I have the same problem with a small twist: align doesn't work for me. I use eqnarray because it allows me to have one column aligned centrally, whereas align only seems to allow left- and right justified columns.

Specifically, I want to do the following:

Code: Select all

\begin{eqnarray}
  x &=& y+z \\
  & \stackrel{\text{[by of Lemma A]}}{=} & y+w \\

  \intertext{Now, we can prove the theorem:}

  r & \stackrel{\text{[by Lemma B]}}{=} & x \\
  &=& y+w
\end{eqnarray}
The equality signs are of different widths because of the \stackrel{}{}. Hence the column containing the equality signs must be center aligned in order for the equality signs to line up.

So, is there any way to allow both intertext and center-aligned columns?
That is a bad syntax in writing, fine for blackboard, but should not be used in typeset text. Other than that it also looks horrible. much better to write this a real text, perhaps using \intertext between the lines, and then leave the math alone. People have to read and understand your text.
svensandberg
Posts: 2
Joined: Wed Feb 11, 2009 10:59 am

eqnarray + lines of text?

Post by svensandberg »

Thanks localghost, my problem is exactly that described in the post you refer to. A MWE would be:

Code: Select all

\begin{align}
  x &= y \\
  &\stackrel{\text{by Lemma 1}}{=} z
\end{align}
The solution in the other thread works ok, but is a bit tedious since I have to type in the width of columns manually:

Code: Select all

\begin{align}
  x &\qquad=\qquad y \\
  &\stackrel{\mathclap{\text{by Lemma 1}}}{\qquad=\qquad} z
\end{align}
Anyways, it's ok, I will use this.

(It would be more convenient if there was an align-like environment that allowed specifying the alignment of each column individually:

Code: Select all

\begin{alignX}{rcl}
  x &=& y \\
  &\stackrel{\text{by Lemma 1}}{=}& z
\end{alignX}
)

daleif, I agree it's not a good idea in the examples above because the motivation can come in the surrounding text, but those are just minimized examples created to make the forum thread readable. In a very long derivation, it can become too cumbersome to explain the steps in surrounding text, especially when equalities and inequalities are mixed ("the first equality is motivated by Lemma A; the first inequality by Lemma B; the second equality by Lemma C ..."). stackrel has been used in scientific publications. It is a quite clear and compact way to motivate each step, which is useful since many conferences have very tight space limits for papers. Do you have any other suggestions for delivering the same message without losing clarity or compactness?

Thanks to both of you for very quick resonses!
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: eqnarray + lines of text?

Post by daleif »

To me that is just another sign of the focus on good typography in scientific publications. No one cares anymore.

There are many publications that recommend using words instead of symbole for things like $\forall x$ etc.

A bonus from using inter formula comments is that page breaks are allowed at these comments.
Post Reply