I'm trying to generate the following output in LaTeX: enter image description here

However I am failing pretty hard at aligning those correctly, this is what I've tried so far:

&(a)\hspace{20pt}\lfloor{n/2}\rfloor &< p &\leq\hspace{19pt} n &\Rightarrow {l}_{p}(n\wr)&=1 \\
&(b)\hspace{20pt}\lfloor{n/3}\rfloor &< p &\leq \lfloor{n/2}\rfloor &\Rightarrow {l}_{p}(n\wr)&=0 \\
&(c)\hspace{20pt}\sqrt{n} &< p &\leq \lfloor{n/3}\rfloor &\Rightarrow {l}_{p}(n\wr)&=\lfloor{n/p}\rfloor\mod 2\\
&(d)\hspace{20pt}2 &< p &\leq \sqrt{n} &\Rightarrow {l}_{p}(n\wr)&<\log_2(n)\\
&(d)\hspace{20pt}{} p &= 2 &\Rightarrow {l}_{p}(n\wr)={\sigma}_{2}(\lfloor{n/2}\rfloor)

How can I do this alignment the right way as presented in the example?


For multiple points (and no big spacing between the blocks) there is alignat. Let's examine your problem, recalling that alignat makes pairs of “right aligned/left aligned” columns.

You have: left aligned column (for the item labels); right aligned column (for the lower bounds); left aligned column (for the relations); right aligned column (for the variable); left aligned column (for the upper bounds); column that can be either left or right aligned (the arrows); left aligned column (for the final conditions).

So we should have

&\lfloor n/2\rfloor
&&\le n

and we should repeat the pattern. We have a total of eight &, which makes for five pairs. The empty group after the relation is to ensure correct spacing. I use \implies that adds some space at either end by itself. I took advantage from the fact that the final condition all have the same structure, so the alignment is automatic; otherwise, follow the same pattern analysis.



&\text{(a)}\qquad &\lfloor n/2\rfloor &<{} &p &\leq n                  &\implies &l_{p}(n\wr)=1 \\
&\text{(b)}\qquad &\lfloor n/3\rfloor &<{} &p &\leq \lfloor n/2\rfloor &\implies &l_{p}(n\wr)=0 \\
&\text{(c)}\qquad &\sqrt{n}           &<{} &p &\leq \lfloor n/3\rfloor &\implies &l_{p}(n\wr)=\lfloor n/p\rfloor \bmod 2\\
&\text{(d)}\qquad &2                  &<{} &p &\leq \sqrt{n}           &\implies &l_{p}(n\wr)<\log_2(n)\\
&\text{(e)}\qquad &                   &    &p &= 2                     &\implies &l_{p}(n\wr)=\sigma_{2}(\lfloor n/2\rfloor)


I removed all the useless braces (none is needed for \lfloor x\rfloor). Note that “mod” as a binary operation should be \bmod, not \mod.

You may want to consider a space saving macro \floor:




&\text{(a)}\qquad &\floor{n/2} &<{} &p &\leq n           &\implies &l_{p}(n\wr)=1 \\
&\text{(b)}\qquad &\floor{n/3} &<{} &p &\leq \floor{n/2} &\implies &l_{p}(n\wr)=0 \\
&\text{(c)}\qquad &\sqrt{n}    &<{} &p &\leq \floor{n/3} &\implies &l_{p}(n\wr)=\floor{n/p} \bmod 2\\
&\text{(d)}\qquad &2           &<{} &p &\leq \sqrt{n}    &\implies &l_{p}(n\wr)<\log_2(n)\\
&\text{(e)}\qquad &            &    &p &= 2              &\implies &l_{p}(n\wr)=\sigma_{2}(\floor{n/2})


enter image description here


For example can you use alignat instead of align. I prette printed your code to see better where the columns are. See that I doubled the last two & in each row.






&(a)\hspace{20pt}\lfloor{n/2}\rfloor &< p &\leq\hspace{19pt} n      &&\Rightarrow {l}_{p}(n\wr)&&=1 \\
&(b)\hspace{20pt}\lfloor{n/3}\rfloor &< p &\leq \lfloor{n/2}\rfloor &&\Rightarrow {l}_{p}(n\wr)&&=0 \\
&(c)\hspace{20pt}\sqrt{n}            &< p &\leq \lfloor{n/3}\rfloor &&\Rightarrow {l}_{p}(n\wr)&&=\lfloor{n/p}\rfloor\mod 2\\
&(d)\hspace{20pt}2                   &< p &\leq \sqrt{n}            &&\Rightarrow {l}_{p}(n\wr)&&<\log_2(n)\\
&(d)\hspace{20pt}{} p                &= 2 &                         &&\Rightarrow {l}_{p}(n\wr)&&={\sigma}_{2}(\lfloor{n/2}\rfloor)



enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.