bobdu.cc

Follow me on GitHub

Definitions by cases (piecewise functions) 分段函数


tags : latex


Use \begin{cases}…\end{cases}. End each case with a \\, and use & before parts that should be aligned. 使用 \begin{cases}…\end{cases} 。用 \\ 来结束每一段,把 & 放在要对齐的部分前。

For example, you get this: 举个例子,你要得到它:

by writing this: 需要这样写:

$$
f(n) =
\begin{cases}
n/2,  & \text{if $n$ is even} \\
3n+1, & \text{if $n$ is odd}
\end{cases}
$$

The brace can be moved to the right: 大括号可以移动到右边:

by writing this: 这样写:

$$
\left.
\begin{array}{l}
\text{if $n$ is even:}&n/2\\
\text{if $n$ is odd:}&3n+1
\end{array}
\right\}
=f(n)
$$

To get a larger vertical space between cases we can use \\[2ex] instead of \\. For example, you get this: 用 \\[2ex] 代替 \\ 可以在两行选择之间留下更大的垂直空间。举个例子,你要得到它:

by writing this: 这样写:

$$
f(n) =
\begin{cases}
\frac{n}{2},  & \text{if $n$ is even} \\[2ex]
3n+1, & \text{if $n$ is odd}
\end{cases}
$$

(An ‘ex’ is a length equal to the height of the letter x; 2ex here means the space should be two exes high.) (一个’ex’的长度等于字母 x 的高度; 2ex 这里表示空隙应该是两个这样的高度。)


本文由BobDu翻译修改自https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference