Latex中使用align来对齐多行公式的排版技巧

时间:2022-10-26 06:37:48

示例显示的结果如下:

Latex中使用align来对齐多行公式的排版技巧

Latex中使用align来对齐多行公式的排版技巧

Latex代码如下:

\documentclass{article}
\pagestyle{empty}
\setcounter{page}{6}
\setlength\textwidth{266.0pt}
\usepackage{CJK}
\usepackage{amsmath}

\begin{CJK}{GBK}{song}
\begin{document}

\begin{align}
  (a + b)^3  &= (a + b) (a + b)^2        \\
             &= (a + b)(a^2 + 2ab + b^2) \\
             &= a^3 + 3a^2b + 3ab^2 + b^3
\end{align}
\begin{align}
  x^2  + y^2 & = 1                       \\
  x          & = \sqrt{1-y^2}
\end{align}
This example has two column-pairs.
\begin{align}    \text{Compare }
  x^2 + y^2 &= 1               &
  x^3 + y^3 &= 1               \\
  x         &= \sqrt   {1-y^2} &
  x         &= \sqrt[3]{1-y^3}
\end{align}
This example has three column-pairs.
\begin{align}
    x    &= y      & X  &= Y  &
      a  &= b+c               \\
    x'   &= y'     & X' &= Y' &
      a' &= b                 \\
  x + x' &= y + y'            &
  X + X' &= Y + Y' & a'b &= c'b
\end{align}

This example has two column-pairs.
\begin{flalign}  \text{Compare }
  x^2 + y^2 &= 1               &
  x^3 + y^3 &= 1               \\
  x         &= \sqrt   {1-y^2} &
  x         &= \sqrt[3]{1-y^3}
\end{flalign}
This example has three column-pairs.
\begin{flalign}
    x    &= y      & X  &= Y  &
      a  &= b+c               \\
    x'   &= y'     & X' &= Y' &
      a' &= b                 \\
  x + x' &= y + y'            &
  X + X' &= Y + Y' & a'b &= c'b
\end{flalign}

This example has two column-pairs.
\renewcommand\minalignsep{0pt}
\begin{align}    \text{Compare }
  x^2 + y^2 &= 1               &
  x^3 + y^3 &= 1              \\
  x         &= \sqrt   {1-y^2} &
  x         &= \sqrt[3]{1-y^3}
\end{align}
This example has three column-pairs.
\renewcommand\minalignsep{15pt}
\begin{flalign}
    x    &= y      & X  &= Y  &
      a  &= b+c              \\
    x'   &= y'     & X' &= Y' &
      a' &= b                \\
  x + x' &= y + y'            &
  X + X' &= Y + Y' & a'b &= c'b
\end{flalign}

\renewcommand\minalignsep{2em}
\begin{align}
  x      &= y      && \text{by hypothesis} \\
      x' &= y'     && \text{by definition} \\
  x + x' &= y + y' && \text{by Axiom 1}
\end{align}

\begin{equation}
\begin{aligned}
  x^2 + y^2  &= 1               \\
  x          &= \sqrt{1-y^2}    \\
 \text{and also }y &= \sqrt{1-x^2}
\end{aligned}               \qquad
\begin{gathered}
 (a + b)^2 = a^2 + 2ab + b^2    \\
 (a + b) \cdot (a - b) = a^2 - b^2
\end{gathered}      \end{equation}

\begin{equation}
\begin{aligned}[b]
  x^2 + y^2  &= 1               \\
  x          &= \sqrt{1-y^2}    \\
 \text{and also }y &= \sqrt{1-x^2}
\end{aligned}               \qquad
\begin{gathered}[t]
 (a + b)^2 = a^2 + 2ab + b^2    \\
 (a + b) \cdot (a - b) = a^2 - b^2
\end{gathered}
\end{equation}
\newenvironment{rcase}
    {\left.\begin{aligned}}
    {\end{aligned}\right\rbrace}

\begin{equation*}
  \begin{rcase}
    B' &= -\partial\times E          \\
    E' &=  \partial\times B - 4\pi j \,
  \end{rcase}
  \quad \text {Maxwell's equations}
\end{equation*}

\begin{equation} \begin{aligned}
  V_j &= v_j                      &
  X_i &= x_i - q_i x_j            &
      &= u_j + \sum_{i\ne j} q_i \\
  V_i &= v_i - q_i v_j            &
  X_j &= x_j                      &
  U_i &= u_i
\end{aligned} \end{equation}

\begin{align}
  A_1 &= N_0 (\lambda ; \Omega')
         -  \phi ( \lambda ; \Omega')   \\
  A_2 &= \phi (\lambda ; \Omega')
            \phi (\lambda ; \Omega)     \\
\intertext{and finally}
  A_3 &= \mathcal{N} (\lambda ; \omega)
\end{align}
\end{CJK}
\end{document}

编译命令如下:

pdflatex main
pdflatex main