markdown多行公式对齐

  • Post author:
  • Post category:其他


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}


参考资料:


[1]TeX:

How can I align multirow and multicolumn equations?