跳到主要内容

Fractions_and_Binomials

分数和二项式

这篇文章解释了如何对分数和二项式系数进行排版,从以下使用amsmath软件包的例子开始。

\documentclass{article}
\usepackage{amsmath}
\begin{document}
The binomial coefficient, \(\binom{n}{k}\), is defined by the expression:
\[
\binom{n}{k} = \frac{n!}{k!(n-k)!}
\]
\end{document}

通过在文件序言中添加以下一行来加载amsmath包。

\usepackage{amsmath}

编译结果如下:

显示分式

分数的视觉外观会发生变化,这取决于它们是作为段落的一部分出现在行内,还是作为独立的材料显示在自己的行内。下一个例子展示了这些视觉外观的变化。

\documentclass{article}
% Using the geometry package to reduce
% the width of help article graphics
\usepackage[textwidth=8cm]{geometry}
\begin{document}
Fractions can be used inline within the paragraph text, for
example \(\frac{1}{2}\), or displayed on their own line,
such as this:
\[\frac{1}{2}\]
\end{document}

文本风格的分数

下面的例子演示了通过使用amsmath软件包提供的 \text{...} 命令来排版纯文本的分数。\text{...}命令用于防止LaTeX将文本排版为普通的数学内容。

\documentclass{article}
% Using the geometry package to reduce
% the width of help article graphics
\usepackage[textwidth=8cm]{geometry}
\usepackage{amsmath}% For the \text{...} command
\begin{document}
We use the \texttt{amsmath} package command
\verb|\text{...}| to create text-only fractions
like this:

\[\frac{\text{numerator}}{\text{denominator}}\]

Without the \verb|\text{...}| command the result
looks like this:

\[\frac{numerator}{denominator}\]
\end{document}

排版数学内的大小和间距

由LATEX排版的数学材料的大小和间距是由算法决定的,这些算法应用了用于排版数学的字体中的大小和定位数据。

有时,我们可能需要或希望推翻LATEX选择的默认数学样式--数学元素的大小和间距,这个问题在Overleaf帮助文章《数学模式下的显示样式》中讨论过。

总的来说,数学排版的默认样式可以通过以下命令改变。

\textstyle:应用段落中数学排版的样式。 \displaystyle:应用数学在行中排版的样式。 \脚本风格:应用于下标或上标的风格。 \scriptscriptstyle:应用于二阶下标或上标的样式。 这在下一个例子中得到了证明。

\documentclass{article}
% Using the geometry package to reduce
% the width of help article graphics
\usepackage[textwidth=9.5cm]{geometry}
\begin{document}

Fractions typeset within a paragraph typically look like this: \(\frac{3x}{2}\). You can force \LaTeX{} to use the larger display style, such as \( \displaystyle \frac{3x}{2} \), which also has an effect on line spacing. The size of maths in a paragraph can also be reduced: \(\scriptstyle \frac{3x}{2}\) or \(\scriptscriptstyle \frac{3x}{2}\). For the \verb|\scriptscriptstyle| example note the reduction in spacing: characters are moved closer to the \textit{vinculum} (the line separating numerator and denominator).

Equally, you can change the style of mathematics normally typeset in display style:

\[f(x)=\frac{P(x)}{Q(x)}\quad \textrm{and}\quad \textstyle f(x)=\frac{P(x)}{Q(x)}\quad \textrm{and}\quad \scriptstyle f(x)=\frac{P(x)}{Q(x)}\]
\end{document}

连续分数

\documentclass{article}
% Using the geometry package to reduce
% the width of help article graphics
\usepackage[textwidth=9.5cm]{geometry}
% Load amsmath to access the \cfrac{...}{...} command
\usepackage{amsmath}
\begin{document}
Fractions can be nested but, in this example, note how the default math styles, as used in the denominator, don't produce ideal results...

\[ \frac{1+\frac{a}{b}}{1+\frac{1}{1+\frac{1}{a}}} \]

\noindent ...so we use \verb|\displaystyle| to improve typesetting:

\[ \frac{1+\frac{a}{b}} {\displaystyle 1+\frac{1}{1+\frac{1}{a}}} \]

Here is an example which uses the \texttt{amsmath} \verb|\cfrac| command:

\[
a_0+\cfrac{1}{a_1+\cfrac{1}{a_2+\cfrac{1}{a_3+\cdots}}}
\]

Here is another example, derived from the \texttt{amsmath} documentation, which demonstrates left
and right placement of the numerator using \verb|\cfrac[l]| and \verb|\cfrac[r]| respectively:
\[
\cfrac[l]{1}{\sqrt{2}+
\cfrac[r]{1}{\sqrt{2}+
\cfrac{1}{\sqrt{2}+\dotsb}}}
\]
\end{document}


示例:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\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}