1. 程式人生 > >markdown多行公式對齊

markdown多行公式對齊

http://sparkandshine.net/latex-use-notes-mathematical-formula/

1. 公式多行多列對齊

當討論一個函式因自定義變數取值不同而表達不同時,通常是寫一個大括號,用cases完成,原始碼如下:

  1. \begin{equation}
  2. \begin{cases}
  3. f(x)=\frac{1}{12} \cdot x \quad g(x)= \frac{1}{24} \cdot x,& x<12 \\
  4. f(x)=1 \quad g(x)= \frac{1}{8} \cdot x -1,&12 \le x <16 \\
  5. f(x)=
    1 \quad g(x)=1,& x \ge 16
  6. \end{cases}
  7. \end{equation}

結果如下:

image

你也看到了,上面的等式不夠美觀,g(x)不對齊。期待的結果是這樣的:

image

原始碼如下:

  1. \begin{equation}
  2. \left\{\begin{aligned}
  3. f(x)&=\tfrac{1}{12} \cdot r,& g(x)&= \tfrac{1}{24} \cdot x,& x&<12 \\
  4. f(x)&=1,&g(x)&= \tfrac{1}{8} \cdot x
    -1,&12&\le x <16 \\
  5. f(x)&=1,&g(x)&=1,& x &\ge 16
  6. \end{aligned}
  7. \right.
  8. \end{equation}