TransWikia.com

align* environment: "=" is not aligned correctly

TeX - LaTeX Asked by firework on June 24, 2021

Source Code:

    begin{align*}
     & = frac{frac{a}{c} - frac{b}{d}}{frac{a}{c} + frac{b}{d}} - frac{a-b}{a+b} & = frac{alpha a - b}{alpha a + b} - frac{a-b}{a+b}
      & = frac{2(alpha - 1)ab}{alpha a^2+(1+alpha)ab+b^2} & = frac{2(alpha - 1)}{alpha beta +(1+alpha) + frac{1}{beta}}
end{align*}

We can see that in the first row second column, the "=" is not aligned correctly with the second row.
enter image description here

One Answer

You're not using the syntax of the align* environment correctly: If you have more than one alignment point per row and wish the material in the second group to be aligned on the = symbols instead of flush-right, you need to use &&=, not &=.

That said, I'd use an alignat* environment instead of an align* environment in order to avoid creating a needless gap between the two groups. Furthermorem, as @egreg has pointed out in a comment, there may not even be a need to align the right-hand set of equations on their = symbols -- at least not for the sample equations you provided.

enter image description here

documentclass{article}
usepackage{amsmath,xcolor}
begin{document}
textcolor{red}{incorrect}
    begin{align*}
    &= frac{frac{a}{c}-frac{b}{d}}{frac{a}{c} + frac{b}{d}} - frac{a-b} {a+b} 
    &= frac{alpha a - b}{alpha a + b} - frac{a-b}{a+b}
    &=frac{2(alpha - 1)ab}{alpha a^2+(1+alpha)ab+b^2}
    &=frac{2(alpha - 1)}{alpha beta +(1+alpha) + frac{1}{beta}}
    end{align*}

textcolor{red}{correct but unattractive}
    begin{align*}
    &= frac{frac{a}{c}-frac{b}{d}}{frac{a}{c} + frac{b}{d}} - frac{a-b} {a+b} 
    &&= frac{alpha a - b}{alpha a + b} - frac{a-b}{a+b}
    &=frac{2(alpha - 1)ab}{alpha a^2+(1+alpha)ab+b^2}
    &&=frac{2(alpha - 1)}{alpha beta +(1+alpha) + frac{1}{beta}}
    end{align*}

textcolor{red}{better: use texttt{alignat*} instead of texttt{align*}}
    begin{alignat*}{2}
    &= frac{frac{a}{c}-frac{b}{d}}{frac{a}{c} + frac{b}{d}} - frac{a-b} {a+b} 
    &&= frac{alpha a - b}{alpha a + b} - frac{a-b}{a+b}
    &=frac{2(alpha - 1)ab}{alpha a^2+(1+alpha)ab+b^2}
    &&=frac{2(alpha - 1)}{alpha beta +(1+alpha) + frac{1}{beta}}
    end{alignat*}

textcolor{red}{even better: don't align the second set of texttt{=} symbols}
    begin{align*}
    &= frac{frac{a}{c}-frac{b}{d}}{frac{a}{c} + frac{b}{d}} - frac{a-b} {a+b} 
     = frac{alpha a - b}{alpha a + b} - frac{a-b}{a+b}
    &=frac{2(alpha - 1)ab}{alpha a^2+(1+alpha)ab+b^2}
     =frac{2(alpha - 1)}{alpha beta +(1+alpha) + frac{1}{beta}}
    end{align*}
end{document}

Correct answer by Mico on June 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP