latex

How Do You Write Fractions in LaTex

Is there a more common element in mathematics than fractions? I suppose not; after all, numbers and expressions going top and others at the bottom is somewhat the definition of math. LaTex knows this and provides you with easy methods to create and use fractions in your documents.

Throughout this tutorial, we will dive into how to implement fractions using LaTeX.

How to Write Simple Fractions in LaTeX

To create fractions, you need to import the amsmathpackage in the preamble.

Once you have the package imported, you can use the \frac and insert the numerator and denominator.

\documentclass{article}

\usepackage[utf8]{inputenc}

\begin{document}

\[

\frac{3}{4}

\]

\end{document}

The above code results in the following.

You can display a fraction inline a block of text by using brackets, as shown in the example code below:

\documentclass{article}

\usepackage[utf8]{inputenc}

\begin{document}

Peter spends \(\frac{1}{2} \), of her salary on house renovations and \(\frac{1}{4} \) on food and shopping. What fraction of her salary was left?

\end{document}

Once you run the markup above, you will see the equations displayed inline with the text as:

The following is an example of a fraction with superscripts and polynomial values.

\documentclass{article}

\usepackage[utf8]{inputenc}

\begin{document}

More Fractions

\[

(a + b)^n = \sum^\alpha_{k=0}\binom{n}{k}a^{n-k}b^k

\]

\end{document}

The output value for this is below:

How to Create Continued Fractions In LaTeX

LaTex also allows you to create nested fractions. To do this, pass another fraction as the denominator.

Here is an example:

\documentclass{article}

\usepackage[utf8]{inputenc}

\usepackage{amsmath}

\begin{document}

\[

\frac{\frac {1}{x} - \frac{i}{y} }{\frac{1}{xy}}

\]

\end{document}

The output for this is:

Conclusion

In this guide, we discussed how to create simple fractions and nested fractions in LaTex documents.

Refer to the documentation to learn more.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list