GeneralLeft alignment of formulas with eqnarray

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
avp3000
Posts: 49
Joined: Thu Nov 15, 2007 4:22 pm

Left alignment of formulas with eqnarray

Post by avp3000 »

Hello,

I know that if I want formulas to be aligned left when using \begin{equation}, I just need to add [fleqn] to the \documentclass options. However, this doesn't seem to work with \begin{eqnarry}. Here is my problem:

\begin{eqnarray}
({\hat{C_1}},0)={Y_1}+{\frac{Y_2}{1+r}}=B_0 {\mbox{ n.P.}} (\frac{Y_2}{1+r})*(1+r) \mbox{ - Alles wird in der ersten Periode konsumiert}\\
(0,\hat{C_2})=Y_2+Y_1(1+r)=D\mbox{ - Alles wird in der zweiten Periode konsumiert}
\end{eqnarray}

The second line is not left aligned, but centered.

Does anyone has a solution?

Cheers
Alex

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
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Left alignment of formulas with eqnarray

Post by gmedina »

The solution is not to use eqnarray. Here you can read the reasons. You can use then align (or align*) environments of the amsmath package instead.

Edit: since you speak German, the original German version of l2tabu can be better for you. You can find it here.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Left alignment of formulas with eqnarray

Post by localghost »

You are using the wrong environment in the wrong way. gmedina has already made suggestions to do that much better. More about typesetting mathematical equations can be found in mathmode.
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Left alignment of formulas with eqnarray

Post by Juanjo »

gmedina and localghost have already suggested to move to the amsmath environments. Add \usepackage{amsmath} to the preamble and try this:

Code: Select all

\begin{align}
  (\hat{C_1},0)&=Y_1+\frac{Y_2}{1+r}=B_0 \text{ n.P.} 
     \left(\frac{Y_2}{1+r}\right)*(1+r) 
     - \text{Alles wird in der ersten Periode konsumiert}, \\
  (0,\hat{C_2})&=Y_2+Y_1(1+r)=D - \text{Alles wird in der zweiten
      Periode konsumiert}.
\end{align}
Is that what you wanted? Please note that you were using superfluous parentheses and some delimiters hadn't the right size. In math mode it is also recommended to use \text instead of \mbox. Finally, since I don't understand German, I don't know if the minus sign before "Alles" is really a math sign (in which case it should go out of the text box, as I'd written) or it is just a mark you add.
avp3000
Posts: 49
Joined: Thu Nov 15, 2007 4:22 pm

Re: Left alignment of formulas with eqnarray

Post by avp3000 »

Hi there everybody,

Thanks a lot for your useful advices and links, the documents you referred me to seem really useful. {align} seems a nice environment, too. I think my biggest mistake was what I was trying to do in the first place. I tried to write an equation, than comment it with a text and than add the equation number, which is probably not the best idea from an aesthetical point of view. Nevertheless, I followed your advice and did use the \begin{align} environment, however in that case the numbering for each line appeared on the following line (and not on the same as I wanted to). That's why I decided that I will just have the two equations without any text and than I will comment on them in the paragraph after!


P.S. How do you do this trick with taking a snapshot of that part of the pdf, which is relevant and than posting it together with the LaTeX-code?
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Left alignment of formulas with eqnarray

Post by Juanjo »

Just for fun, try the following code:

Code: Select all

\begin{align}
  (\hat{C_1},0)&=Y_1+\frac{Y_2}{1+r}=B_0 \text{ n.P.} 
     \left(\frac{Y_2}{1+r}\right)*(1+r) 
     &\Longleftarrow&\ \parbox[t]{0.3\linewidth}{Alles wird in der ersten 
     Periode konsumiert} \\
  (0,\hat{C_2})&=Y_2+Y_1(1+r)=D 
     &\Longleftarrow&\ \parbox[t]{0.3\linewidth}{Alles wird in der zweiten
     Periode konsumiert}
\end{align}

\begin{alignat}{2}
  (\hat{C_1},0)&=Y_1+\frac{Y_2}{1+r}=B_0 \text{ n.P.} 
     \left(\frac{Y_2}{1+r}\right)*(1+r)\quad
     &\Longleftarrow&\ \parbox[t]{0.3\linewidth}{Alles wird in der ersten 
     Periode konsumiert} \\
  (0,\hat{C_2})&=Y_2+Y_1(1+r)=D 
     &\Longleftarrow&\ \parbox[t]{0.3\linewidth}{Alles wird in der zweiten
     Periode konsumiert}
\end{alignat}
Replace 0.3\linewidth by a different length if required. This code shows:
  • that align supports multiple points of alignment between equations,
    that one can include boxes in formulas containing long text,
    that there exists environments similar to align that one could sometimes need.
P.S. How do you do this trick with taking a snapshot of that part of the pdf, which is relevant and than posting it together with the LaTeX-code?


Taking a snapshop is platform dependent. To post LaTeX code, simply click on the box "Code" just above the window where you write the post text and paste the code at the cursor position (between the bracketed "code" and "/code" labels).
inoh
Posts: 1
Joined: Sun Jul 14, 2024 4:46 pm

Left alignment of formulas with eqnarray

Post by inoh »

Try this:

\begin{flalign}
x &= a + b &&\\
c &= d + e &&\\
f &= g + h &&
\end{flalign}
Post Reply