2

How do I make aligned equations with multiple "&" to not have unnecessary spaces like the one in the red box in the attached picture. Here is my code:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{align*}
    B_2 > B_1 & \iff & \log B_2 &> \log B_1 \\
              & \iff & \log B_2 - \log B_0 &> \log B_1 - \log B_0 \\
              & \iff & -2.5 \left( \log B_2 - \log B_0 \right) &< -2.5 \left( \log B_1 - \log B_0 \right) \\
              & \iff & -2.5 \log B_2 + 2.5 \log B_0 &< -2.5 \log B_1 +2.5 \log B_0
\end{align*}


\end{document}

missing alt text

8
  • Note: You cannot (and should not) use the whole problem description inclusive code block as image alt text. I've corrected this and also corrected the markdown code marks (replaced the ''' by ```). Now, the image is visible and also the code is shown as code. Please have a look into my changes.
    – cabohah
    Commented Aug 3 at 13:16
  • @cabohah Thank you. I will take note of this as future reference. Sorry for the inconvenience Commented Aug 3 at 13:22
  • 3
    The code you've posted does not generate either of the screenshots. Please clarify what it is that you're trying to achieve.
    – Mico
    Commented Aug 3 at 13:28
  • I putted the wrong code earlier. I have edited it. Commented Aug 3 at 13:31
  • "to not have ... like the one" is a bit unclear (does "not" apply only to "have" or also to "like the one in the red box"?). From looking at the picture, it looks like the unboxed is what you have, and the red box is what you want. Is that correct?
    – Teepeemm
    Commented Aug 3 at 13:33

1 Answer 1

6

I suggest you switch from an align* environment to an alignat*{2} environment.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{2}
    B_2 > B_1 > 0 
       & \iff & \log B_2            &> \log B_1 \\
       & \iff & \log B_2 - \log B_0 &> \log B_1 - \log B_0 \\
       & \iff & -2.5 (\log B_2 -\log B_0)  &< -2.5 ( \log B_1 - \log B_0 ) \\
       & \iff & -2.5 \log B_2 +2.5\log B_0 &< -2.5 \log B_1 +2.5\log B_0
\end{alignat*}
\end{document}
4
  • 1
    This solved my problem. Thank you! Commented Aug 3 at 13:39
  • @Mico the {2} means two pairs of alihnment right?
    – yannisl
    Commented Aug 3 at 14:27
  • 2
    @yannisl - There are two ways to think about this parameter. The more intuitive one is that it denotes the number of (logical) columns of math-y expressions; for the example at hand, the first column ("B_2>B_1>0") occupies just one row, while the second column (arranged around the < and > symbols) occupies all four rows. The second way is purely mechanical: you count the & symbols per row, add 1, and dividesby 2: (3+1)/2=2.
    – Mico
    Commented Aug 3 at 14:37
  • Thanks, me always thought in pairs and considered a row as if is a table row like ` a&b &c &\` . your formula also makes sense. I rarely use alignat to be honest.
    – yannisl
    Commented Aug 3 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .