Math & Scienceamsmath | Alignment of multi-lined Formula

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
chrizzl83
Posts: 4
Joined: Fri Jan 25, 2013 5:33 pm

amsmath | Alignment of multi-lined Formula

Post by chrizzl83 »

Hi there,

I am new to LaTeX and I have the following problem: There are two align environments. The second one is displayed correctly on the left of the page, but the first is indented. The {flushleft} is not working. What is wrong here?

Code: Select all

\begin{flushleft}
\begin{align}
 & \text{minimize}\; &  & \sum_{c\in C_{t_{k}}}\sum_{e=1}^{P_{c}}\sum_{t\in T}o_{c,t}^{\text{pp}}(e)*y_{c,e,t}
\end{align}

\par\end{flushleft}

\begin{align}
 & \text{subject to\;}\nonumber \\
 & \sum_{c\in C_{t_{k}}}\sum_{d\in D_{c}}\Theta_{i}^{d}*z_{d}\geq1 &  &  & \forall & i\in F\setminus F_{t_{k}}^{\text{pas}}\label{eq:ASPfix_assignAllFlights-1}
\end{align}
This resulting output is attached.

Any help is appreciated!


Cheers
C
Attachments
equation-alignment.png
equation-alignment.png (18.1 KiB) Viewed 9074 times
Last edited by localghost on Fri Jan 25, 2013 6:48 pm, edited 1 time in total.

Recommended reading 2024:

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

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

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

amsmath | Alignment of multi-lined Formula

Post by localghost »

I know this typeset in another way. No need for {flushleft} (which doesn't work here anyway). Perhaps you are looking for something like this with alignat from amsmath.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}  % loads »amsmath«

\begin{document}
    \begin{alignat}{2}
     \text{minimize}\quad &  \sum_{c\in C_{t_{k}}}\sum_{e=1}^{P_{c}}\sum_{t\in T}o_{c,t}^{\text{pp}}(e)*y_{c,e,t} \\
     \text{subject to}\quad & \sum_{c\in C_{t_{k}}}\sum_{d\in D_{c}}\Theta_{i}^{d}*z_{d}\geq1 &&\qquad\forall  i\in F\setminus F_{t_{k}}^{\text{pas}}\label{eq:ASPfix_assignAllFlights-1}
    \end{alignat}
\end{document}
Further reading:

Best regards and welcome to the board
Thorsten
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: amsmath | Alignment of multi-lined Formula

Post by svend_tveskaeg »

The link to Herbert Voss' notes seems to be wrong; here is one that works:

http://mirrors.ctan.org/info/math/voss/ ... thmode.pdf
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

amsmath | Alignment of multi-lined Formula

Post by Stefan Kottwitz »

The link works, it's just to the CTAN information page instead of straight to the document. To not have the need to remember such links, I use the doc button when writing, which links mathmode to mathmode.

Stefan
LaTeX.org admin
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: amsmath | Alignment of multi-lined Formula

Post by svend_tveskaeg »

Hmmm! It is not the same link now as when I tried it. This one works indeed.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

amsmath | Alignment of multi-lined Formula

Post by localghost »

svend_tveskaeg wrote:Hmmm! It is not the same link now as when I tried it. This one works indeed.
No need to worry. I corrected my link after I made a mistake. Perhaps coincidentally with you trying it out.
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: amsmath | Alignment of multi-lined Formula

Post by svend_tveskaeg »

Okay. :)
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
chrizzl83
Posts: 4
Joined: Fri Jan 25, 2013 5:33 pm

amsmath | Alignment of multi-lined Formula

Post by chrizzl83 »

Hey,

thanks for the link to the docu!

I don't understand why I should use alignat here, because I don't need to have several align environments side by side. The code you supplied doesn't solve the problem either. The first line is still indented.


localghost wrote:I know this typeset in another way. No need for {flushleft} (which doesn't work here anyway). Perhaps you are looking for something like this with alignat from amsmath.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}  % loads »amsmath«

\begin{document}
    \begin{alignat}{2}
     \text{minimize}\quad &  \sum_{c\in C_{t_{k}}}\sum_{e=1}^{P_{c}}\sum_{t\in T}o_{c,t}^{\text{pp}}(e)*y_{c,e,t} \\
     \text{subject to}\quad & \sum_{c\in C_{t_{k}}}\sum_{d\in D_{c}}\Theta_{i}^{d}*z_{d}\geq1 &&\qquad\forall  i\in F\setminus F_{t_{k}}^{\text{pas}}\label{eq:ASPfix_assignAllFlights-1}
    \end{alignat}
\end{document}
Further reading:

Best regards and welcome to the board
Thorsten
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

amsmath | Alignment of multi-lined Formula

Post by Stefan Kottwitz »

chrizzl83 wrote:why I should use alignat here, because I don't need to have several align environments side by side.
With alignat you could align at several places, make several columns.
chrizzl83 wrote:The first line is still indented.
You place the & for the alignment position differently. For example:

Code: Select all

\begin{alignat}{3}
 &\text{minimize}\quad &&  \sum_{c\in C_{t_{k}}}\sum_{e=1}^{P_{c}}\sum_{t\in T}o_{c,t}^{\text{pp}}(e)*y_{c,e,t} \\
 &\text{subject to}\quad && \sum_{c\in C_{t_{k}}}\sum_{d\in D_{c}}\Theta_{i}^{d}*z_{d}\geq1 &&\qquad\forall  i\in F\setminus F_{t_{k}}^{\text{pas}}\label{eq:ASPfix_assignAllFlights-1}
\end{alignat}
Alignment columns are alternating right/left aligned, like rlrlrl in arrays.

If you would like to have completely flushed left equations, you could use the fleqn document class option.

Stefan
LaTeX.org admin
chrizzl83
Posts: 4
Joined: Fri Jan 25, 2013 5:33 pm

amsmath | Alignment of multi-lined Formula

Post by chrizzl83 »

Hey Stefan,

I think you didn't understand my question completely. Maybe I was not precise enough. I cannot add the first equation to the same align environment as the stuff below, because the equation is to long and doesn't fit in the alignment. Therefore I made two align environments. But the problem with this solution is, that the left indentions are different.

I found, that my question is duplicate for this one:

http://www.latex-community.org/forum/vi ... 46&t=12472
Post Reply