2

enter image description here

Is it possible to align the for statements here, without dropping the equation numbers? \hfill and && mess up the placement of the equation numbers for me.

Edit:

Picture of what I get after I tried what was posted as answer

enter image description here

texfan
  • 817

2 Answers2

4

Here is a possible solution (if I understand your request correct):

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\begin{alignat}{2}
  \sum_{\mathclap{p \,=\, 1}}^{i}  s_{tp} - \sum_{\mathclap{p \,=\, 2}}^{i+5}                                       m_{tp} &\leq 0 \qquad
  &&\text{for } i = 1, \dots, 39,\\
  \sum_{\mathclap{p \,=\, i}}^{48} f_{tp} - \sum_{\mathclap{\substack{p \,=\, i-5\\ \hphantom{p \,=\,} -2+1}}}^{46} m_{tp} &\geq 0
  &&\text{for } i = 8, \dots, 48,
\end{alignat}

\end{document}

output

  • It's somehow not working for me: I tried this (just a simple version of your answer): & \sum_{p=i}^{48} f_{tp} - \sum_{\mathclap{p=i-1-2+1}}^{46} m_{tp} \geq 0 \qquad &&\text{ for } i=9,\dots, 48,\\ & \sum_{p=i}^{48} f_{tp} - \sum_{\mathclap{p=i-5-2+1}}^{46} m_{tp} \leq 0 &&\text{ for } i=9,\dots, 48,\\, but the page numbers then moved to a next line. Do you know what could cause that? – texfan Apr 28 '14 at 16:33
  • I've added a picture of what I get now in the OP. – texfan Apr 28 '14 at 16:35
  • @rbm: Do you have the fleqn option somewhere in your document? – Werner Apr 28 '14 at 16:49
  • @Werner Yes I do, I have it with the mathstools package (so \usepackage[fleqn]{mathtools}). Could that cause the problem? – texfan Apr 28 '14 at 16:50
  • @Werner I got rid of the fleqn now, but then I get a rather similar, still incorrect output with the number on the next line. – texfan Apr 28 '14 at 16:54
  • @werner The awkward thing is, that now I tried it in a new align environment, separate of the other equations, it worked. But I prefer it in the same environment. – texfan Apr 28 '14 at 16:57
  • @werner I figured out that the \left( and \right) that were in one of the lines caused the problem. I changed them now, but now the brackets in that line don't look as nice. Very odd. Do you have any clue what I could do to solve that issue? – texfan Apr 28 '14 at 17:42
  • @rbm: There is no \left...\right constructions in your example. Please always post complete, minimal working examples (MWEs). You can use \big-like construction to replicate your \left-\right constructions. See Using \left( & \right) around amsmath's align delimiter (“&”), \left/\right across multiline equation but also Is it ever bad to use \left and \right? – Werner Apr 28 '14 at 17:46
  • @Werner I know, but the equations that I showed in the OP are part of a large block of about 20 equations. So I thought it would not make sense to copy all of them (the \left( and right were in an other equation). Thanks for the suggestion about \big, I'll try that out! – texfan Apr 28 '14 at 17:48
1

Although a minimal working example (MWE) would really be helpful here, like Steven B. already stated, I think I got you.

Try to use mathtools instead of amsmath. It uses amsmath and extends it more, so you can use the \mathclap command. The lower sum limits of the second summation is causing the gap you dislike:

\documentclass{scrartcl}
\usepackage{mathtools}

\begin{document}
\begin{align}
  \sum_{p=1}^{i}s_{tp} - \sum_{p=2}^{i+5}m_{tp} \leq 0 for i = 1,\cdots,39,\\
  \sum_{p=1}^{48}f_{tp} - \sum_{\mathclap{p=i-5-2+1}}^{46}m_{tp} \geq 0 for i = 8,\cdots,48,
\end{align}
\end{document}
Cheesey
  • 385
  • ...where is the alignment around the for as requested? It seems like your post was also cut short. – Werner Apr 28 '14 at 16:22
  • Thanks, but you did not exactly understand what I meant. My mistake, I should have been more specific in the OP. What I want is the part from for to be aligned somewhat more to the right, all at the same level (like in Sven's answer, but that doesn't work for me yet). – texfan Apr 28 '14 at 16:38
  • @Werner: I misunderstood his questions, I thought about a different alignment. My mistake, sorry. – Cheesey Apr 28 '14 at 16:46
  • @Cheesey No problem, I should have been more specific. Do you have an idea what I could change to get it to work (I commented on Sven's solution)? – texfan Apr 28 '14 at 16:48
  • I have read it. Can you please post the full minimal working example - like Sven and I did - so we can see what usepackages, documentclass, options (like fleqn) etc. you are using? Because I just tested your code in the comments and the numbering works fine for me. – Cheesey Apr 28 '14 at 16:57
  • @cheesey, The thing is, I have a whole block of around 20 equations. When I paste the lines I have now in a new align block, everything works as it should. Just when it is in the same block, it does not. And I don't think it'd be handy to post the whole block of equations – texfan Apr 28 '14 at 17:01
  • Hmm, then maybe the problem lies somewhere else. Have you tried to comment out certain lines to see if they cause the problem? – Cheesey Apr 28 '14 at 17:04
  • @Cheesey I was actually already doing that myself too the moment you wrote that. I found out the problem, and it turns out that the \left( and \right) that were in one of the lines caused the problem. I changed them now, but now the brackets in that line don't look as nice. Very odd. – texfan Apr 28 '14 at 17:41