MathJax基础之分段函数 piecewise functions

怎么写分段函数呢?用关键词 {case}

主要格式是 \begin{cases} ... \end{cases},用 \\ 来换行,用 & 来对齐。

举个例子:

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

可以得到:

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

如果想把括号放右边,就这样写:

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

得到:

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

如果想让两行之间的间隔变得更大一些,就可以用 \\[2ex] 代替 \\,接着举例子:

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

得到:

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

注:ex是指字母x的高度,\\[2ex]就表示两倍的字母x的高度。

上一篇 MathJax基础之对齐等式
下一篇 MathJax基础之Array或Table
目录
文章列表
1 Spring Boot RestTemplate 自定义返回码异常处理
Spring Boot RestTemplate 自定义返回码异常处理
2
React Native学习之定时器与手机定位Geolocation API
React Native学习之定时器与手机定位Geolocation API
3
OpenLDAP + phpLDAPadmin
OpenLDAP + phpLDAPadmin
4
数据库结构导出工具DbSchema
数据库结构导出工具DbSchema
5
MySQL加锁实践
MySQL加锁实践
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。