2

This is my code to align this equation

\documentclass[12pt,a4paper]{article}
    \usepackage{amsmath}
    \begin{document}
        \begin{alignat*}{5}
            (a+b)^{4} &=C_{4}^{0} a^{4}&&+C_{4}^{1} a^{3} b&&+C_{4}^{2} a^{2} b^{2}&&+C_{4}^{3} a b^{3}&&+C_{4}^{4} b^{4} \\
            &=a^{4}&&+4 a^{3} b&&+6 a^{2} b^{2}&&+4 a b^{3}&&+b^{4} 
        \end{alignat*} 
    \end{document}

enter image description here

I feel, this is not a nice align. How can I get a nice align?

2
  • 1
    In general, equal sign only must aligned, not for + and minus, etc. and all...
    – MadyYuvi
    Jul 22, 2022 at 4:10
  • 1
    What do you mean with "nice align"? The output of your code is the same like in your picture.
    – Roland
    Jul 22, 2022 at 4:40

1 Answer 1

8

You could employ an array environment to get a "nice align", as you put it:

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage{array}
\newcolumntype{C}{>{{}}c<{{}}} % col. type for relational and binary operators
\newcolumntype{R}{>{\displaystyle}r}

\begin{document}
\[
\renewcommand\arraystretch{1.33}
\setlength\arraycolsep{0pt}
\begin{array}{ *{5}{RC} R }
(a+b)^4 &=& C_4^0 a^4 &+& C_4^1 a^3 b &+& C_4^2 a^2 b^2 &+& C_4^3 a b^3 &+& C_4^4 b^4 \\
        &=&       a^4 &+&     4 a^3 b &+&     6 a^2 b^2 &+&     4 a b^3 &+&       b^4 
\end{array} 
\]

\end{document}

You must log in to answer this question.

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