LaTex 数学之分数和二项式系数
分数和二项式系数是具有相似特征的常见数学元素——一个数字叠加在另一个数字之上。本文解释了如何在L A T E X中对它们进行排版。
在表达式中使用分数和二项式系数很简单。
\usepackage{amsmath}
\begin{document}
The binomial coefficient is defined by the next expression:
\[
\binom{n}{k} = \frac{n!}{k!(n-k)!}
\]
\end{document}
要使这些命令起作用,您必须通过将下一行添加到文件的序言中来 导入包amsmath
\usepackage { amsmath }
显示分数
分数的外观可能会根据上下文而改变
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Fractions can be used alongside the text, for
example \( \frac{1}{2} \), and in a mathematical
display style like the one below:
\[\frac{1}{2}\]
\end{document}
正如您可能已经猜到的那样,该命令\frac{1}{2}
是显示分数的命令。第一对大括号内的文本是分子,第二对大括号内的文本是分母。
此外,分数的文本大小会根据其周围的文本而变化。如果需要,您可以手动设置。
\documentclass{article}
\usepackage{amsmath}
\begin{document}
When displaying fractions in-line, for example \(\frac{3x}{2}\)
you can set a different display style:
\( \displaystyle \frac{3x}{2} \).
This is also true the other way around
\[ f(x)=\frac{P(x)}{Q(x)} \ \ \textrm{and}
\ \ f(x)=\textstyle\frac{P(x)}{Q(x)} \]
\end{document}
该命令\displaystyle
将格式化分数,就好像它处于数学显示模式一样。另一方面,\textstyle
将更改分数的样式,就好像它是文本的一部分一样。
连(嵌套)分数
分数的使用非常灵活,它们可以嵌套以获得更复杂的表达式。
\usepackage{amsmath}
\begin{document}
The fractions can be nested
\[ \frac{1+\frac{a}{b}}{1+\frac{1}{1+\frac{1}{a}}} \]
Now a wild example
\[
a_0+\cfrac{1}{a_1+\cfrac{1}{a_2+\cfrac{1}{a_3+\cdots}}}
\]
\end{document}
前面示例中显示的第二个分数使用\cfrac{}{}
包amsmath
提供的命令(参见介绍),该命令显示嵌套分数而不更改字体大小。特别适用于连分数。
二项式系数
二项式系数是数学表达式中的常见元素,在L A T E X中显示它们的命令与用于分数的命令非常相似。
\usepackage{amsmath}
\begin{document}
The binomial coefficient is defined by the next expression:
\[
\binom{n}{k} = \frac{n!}{k!(n-k)!}
\]
And of course this command can be included in the normal
text flow \(\binom{n}{k}\).
\end{document}
如您所见,该命令\binom{}{}
将使用大括号内传递的参数打印二项式系数。
参考指南
连分数的一个稍微不同但更复杂的例子
\usepackage{amsmath}
\begin{document}
Final example
\newcommand*{\contfrac}[2]{%
{
\rlap{$\dfrac{1}{\phantom{#1}}$}%
\genfrac{}{}{0pt}{0}{}{#1+#2}%
}
}
\[
a_0 +
\contfrac{a_1}{
\contfrac{a_2}{
\contfrac{a_3}{
\genfrac{}{}{0pt}{0}{}{\ddots}
}}}
\]
\end{document}