4
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{3}
    &\text{Case 1: } s^*\leq a&\quad &\hphantom{\leq} 2\beta \leq& 2a\alpha-4\lambda-\tau &\Rightarrow s^* = \frac{2\beta+4\lambda+\tau}{2\alpha}\\
    &\text{Case 2: } a < s^* \leq b&\quad 2a\alpha-4\lambda+\tau &\leq 2\beta \leq& 2b\alpha-4\lambda+\tau &\Rightarrow s^*=\frac{2\beta+4\lambda-\tau}{2\alpha}\\
    &\text{Case 3: } b < s^* \leq c&\quad 2b\alpha-2\lambda+\tau &\leq 2\beta \leq& 2c\alpha-2\lambda+\tau &\Rightarrow s^* = \frac{2\beta+2\lambda-\tau}{2\alpha}\\
    &\text{Case 4: } c < s^* \leq d&\quad 2c\alpha+\tau &\leq 2\beta \leq& 2d\alpha+\tau &\Rightarrow s^* = \frac{2\beta-\tau}{2\alpha}\\
    &\text{Case 5: } d < s^* \leq e&\quad 2d\alpha+2\lambda+\tau &\leq 2\beta \leq& 2e\alpha+2\lambda+\tau & \Rightarrow s^* = \frac{2\beta-2\lambda-\tau}{2\alpha}\\
    &\text{Case 6: } e < s^*&\quad 2e\alpha+4\lambda+\tau &\leq 2\beta \hphantom{\leq}& &\Rightarrow s^* = \frac{2\beta-4\lambda-\tau}{2\alpha}
\end{alignat*}
\end{document}

The above code results in the PDF:

PDF output

Everything is right except the 4th line. Why is the 2d\alpha+\tau aligning right? How can I get it to align immediately with \leq?

Moriambar
  • 11,466
elexhobby
  • 215
  • 2
    Welcome to TeX.SX! Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to help you. Help them help you: remove that one hurdle between you and a solution to your problem. – jub0bs Sep 30 '13 at 18:38

2 Answers2

4

To get a better alignment, you can use the following (and forget about the \hphantoms):

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{alignat*}{9}
  & \text{Case 1: }&      & s^* &\leq a &                          &         &&        2\beta & \leq  {}&& 2a\alpha - 4\lambda &{}- \tau &&{} \Rightarrow {}& s^* &{}={}& \frac{2\beta + 4\lambda + \tau}{2\alpha}\\
  & \text{Case 2: }& a <{}& s^* &\leq b &\quad 2a\alpha - 4\lambda &{}+ \tau &&{} \leq 2\beta & \leq  {}&& 2b\alpha - 4\lambda &{}+ \tau &&{} \Rightarrow {}& s^* &{}={}& \frac{2\beta + 4\lambda - \tau}{2\alpha}\\
  & \text{Case 3: }& b <{}& s^* &\leq c &\quad 2b\alpha - 2\lambda &{}+ \tau &&{} \leq 2\beta & \leq  {}&& 2c\alpha - 2\lambda &{}+ \tau &&{} \Rightarrow {}& s^* &{}={}& \frac{2\beta + 2\lambda - \tau}{2\alpha}\\
  & \text{Case 4: }& c <{}& s^* &\leq d &\quad 2c\alpha            &{}+ \tau &&{} \leq 2\beta & \leq  {}&& 2d\alpha            &{}+ \tau &&{} \Rightarrow {}& s^* &{}={}& \frac{2\beta            - \tau}{2\alpha}\\
  & \text{Case 5: }& d <{}& s^* &\leq e &\quad 2d\alpha + 2\lambda &{}+ \tau &&{} \leq 2\beta & \leq  {}&& 2e\alpha + 2\lambda &{}+ \tau &&{} \Rightarrow {}& s^* &{}={}& \frac{2\beta - 2\lambda - \tau}{2\alpha}\\
  & \text{Case 6: }& e <{}& s^* &       &\quad 2e\alpha + 4\lambda &{}+ \tau &&{} \leq 2\beta &         &&                     &         &&   \Rightarrow {}& s^* &{}={}& \frac{2\beta - 4\lambda - \tau}{2\alpha}
\end{alignat*}

\end{document}

output

David Carlisle
  • 757,742
  • 1
    you've got the spacing around the operators and relations correct -- congrats. but you don't actually need {} before an operator or relation that immediately follows & (it doesn't hurt, though). what you do need (and you've got it right) is {} after an operator or relation that precedes an &. this does seem to confuse people ... – barbara beeton Sep 30 '13 at 20:03
  • @barbarabeeton Can I make you update my answer with the improved code? If I try and remove any of the {} the spacing is no longer correct. – Svend Tveskæg Sep 30 '13 at 20:17
  • 1
    okay, i've tested this, and you're quite right -- if the {} before the + signs are removed, the spacing closes up. i don't think this should happen, but there must be a reason. i'll look into it and report back. (but maybe not today.) – barbara beeton Sep 30 '13 at 20:29
  • please send me your e-mail address (you can use the address on my profile if you don't know my "real" one). i have a brief test that's too complicated for either a comment or chat; it needs more study, but it shows something unexpected that i think will interest you. however, be assured that the answer you have here is solid, and i haven't come up with anything better. – barbara beeton Oct 01 '13 at 20:34
  • @barbarabeeton I have send an email to tech-support@ams.org. – Svend Tveskæg Oct 01 '13 at 20:46
  • Wow! This is more than I'd asked for. Thanks! I'm not sure if this is what you are discussing above, but I don't understand what purpose the {} serve. Also, could you explain when to use & and when to use &&? – elexhobby Oct 01 '13 at 22:48
  • 1
    The {}s are there to get the correct spacing around the operators (+, - and so on) and relations (= and so on). For the alignat usage, see, e.g., section 25.2 in Math mode by Herbert Voß or the amsmath manual. (For n alignment points, 2n-1 &s are needed.) – Svend Tveskæg Oct 01 '13 at 23:10
  • @barbarabeeton Have you found the reason for the unexpected behaviour, Barbara? – Svend Tveskæg Oct 13 '13 at 23:15
  • @SvendTveskæg -- not yet; more complete explanation offline. – barbara beeton Oct 14 '13 at 16:28
1

You can rearrange & to find better alignment, bu instead, recall that - sign are surrounded by two medium spaces (TeXbook, page 167). So if we write:

&\text{Case 4: } c < s^* \leq d&\quad 2c\alpha\phantom{\:-\:2\lambda}+\tau &\leq 2\beta \leq& 2d\alpha\phantom{\:-\:2\lambda}+\tau &\Rightarrow s^* = \frac{2\beta-\tau}{2\alpha}

we will get

enter image description here

Francis
  • 6,183