# Fractions and Binomials

## Contents

# Introduction

This article explains how to typeset fractions and binomial coefficients, starting with the following example which uses the `amsmath`

package:

```
\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}
```

Open this example in Overleaf.

The `amsmath`

package is loaded by adding the following line to the document preamble:

```
\usepackage{amsmath}
```

Here is the output produced:

# Displaying fractions

The visual appearance of fractions will change depending on whether they appear inline, as part of a paragraph, or typeset as standalone material displayed on their own line. The next example demonstrates those changes to visual appearance:

```
\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}
```

Open this example in Overleaf.

This example produces the following output:

**Note**: More information on inline and display versions of mathematics can be found in the Overleaf article Display style in math mode.

Our example fraction is typeset using the `\frac`

command (`\frac{1}{2}`

) which has the general form `\frac{`

.
*numerator*}{*denominator*}

# Text-style fractions

The following example demonstrates typesetting text-only fractions by using the `\text{...}`

command provided by the `amsmath`

package. The `\text{...}`

command is used to prevent LaTeX typesetting the text as regular mathematical content.

```
\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}
```

Open this example in Overleaf.

This example produces the following output:

# Size and spacing within typeset mathematics

The size and spacing of mathematical material typeset by LaTeX is determined by algorithms which apply size and positioning data contained inside the fonts used to typeset mathematics.

Occasionally, it may be necessary, or desirable, to override the default mathematical styles—size and spacing of math elements—chosen by LaTeX, a topic discussed in the Overleaf help article Display style in math mode.

To summarize, the default style(s) used to typeset mathematics can be changed by the following commands:

`\textstyle`

: apply the style used for mathematics typeset in paragraphs;`\displaystyle`

: apply the style used for mathematics typeset on lines by themselves;`\scriptstyle`

: apply the style used for subscripts or superscripts;`\scriptscriptstyle`

: apply the style used for second-order subscripts or superscripts;

which are demonstrated in the next example.

```
\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}
```

This example produces the following output:

# Continued fractions

Fractions can be nested to obtain more complex expressions. The second pair of fractions displayed in the following example both use the `\cfrac`

command, designed specifically to produce continued fractions. To use `\cfrac`

you must load the `amsmath`

package in the document preamble.

```
\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}
```

Open this example in Overleaf.

This example produces the following output:

# A final example

This example demonstrates a more complex continued fraction:

```
\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}
```

Open this example in Overleaf.

This example produces the following output:

# Further reading

For more information see:

## Overleaf guides

- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Using the Overleaf project menu
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Using the History feature
- Debugging Compilation timeout errors
- How-to guides
- Guide to Overleaf’s premium features

## LaTeX Basics

- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Lists
- Errors

## Mathematics

- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Matrices
- Fractions and Binomials
- Aligning equations
- Operators
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts
- Using the Symbol Palette in Overleaf

## Figures and tables

- Inserting Images
- Tables
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package

## References and Citations

- Bibliography management with bibtex
- Bibliography management with natbib
- Bibliography management with biblatex
- Bibtex bibliography styles
- Natbib bibliography styles
- Natbib citation styles
- Biblatex bibliography styles
- Biblatex citation styles

## Languages

- Multilingual typesetting on Overleaf using polyglossia and fontspec
- Multilingual typesetting on Overleaf using babel and fontspec
- International language support
- Quotations and quotation marks
- Arabic
- Chinese
- French
- German
- Greek
- Italian
- Japanese
- Korean
- Portuguese
- Russian
- Spanish

## Document structure

- Sections and chapters
- Table of contents
- Cross referencing sections, equations and floats
- Indices
- Glossaries
- Nomenclatures
- Management in a large project
- Multi-file LaTeX projects
- Hyperlinks

## Formatting

- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Counters
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Footnotes
- Margin notes

## Fonts

## Presentations

## Commands

## Field specific

- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typesetting exams in LaTeX
- Knitr
- Attribute Value Matrices

## Class files

- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class