How to create an absolute value symbol in LaTeX?

# How to create an absolute value symbol in LaTeX?

This post may contain affiliate links that allow us to earn a commission at no expense to you. Learn more

This article aims to show you a simple way to create an absolute value symbol in LaTeX.

By definition, the absolute value or modulus is the non-negative value of x without regard to its sign. But if you need to insert it in your LaTeX documents, today you will learn how to do it.

## Absolute Value Symbol

The most common way to represent the absolute value symbol is using two vertical lines on each side of the expression. For example

There are many commands of ways to insert the absolute value, but in this article, we will focus on the most common ways to write the symbol.

## Absolute Value \mid

The first option is using the command \mid, it generates a vertical line where you type it, therefore you will need two \mid commands for the absolute value, it requires math mode enabled. For example

\begin{document}

Absolute using $\backslash$mid $\mid x+y \mid$

\end{document}

The \mid command has bigger blank spaces on the argument of the absolute value, this is my go-to option to write inline equations.

## Absolute Value Lines

The second option is using the key “|”, your keyboard has it but you can also write it by typing alt + 124. It goes to each side of the argument of the absolute value, and it requires the math mode. As you can see absolute value symbol is not an actual command but rather just a key.

For example,

\begin{document}

Absolute value using “$|$” $|x+z|$

\end{document}

## Absolute Value Vertical Commands

You can also use two commands to create the vertical lines on each side, for the left side you use the command \lvert, and for the right side \rvert, both commands require importing the amsmath package. For example

\documentclass{article}

\usepackage{amsmath}

\begin{document}

Absolute value using $\backslash$lvert and $\backslash$rvert

$$\lvert y + 3 \rvert$$

\end{document}

\lvert stands for left vertical, and \rvert for right vertical. As you can see these commands don’t have a lot of blank space for the argument of the absolute value.

## Resizable Value Symbol

To this point we have only used inline equation, but what about including integrals or summation, you can use all of the options above, for example

\documentclass{article}

\usepackage{amsmath}

\begin{document}

$$|\int x^2 dx|$$

$$\mid \sum_{i=0}^{\infty} \dfrac{x_{i}}{x^2 + 4} \mid$$

$$\lvert \dfrac{x^3+x^2+x+6}{x-9} \rvert$$

\end{document}

As you can see, the vertical bars on each side of the expressions do not have the same height as the argument. To solve this you have to use two commands \left and \right, just before inserting the vertical bars, let’s recreate the example above but using these two new commands,

\documentclass{article}

\usepackage{amsmath}

\begin{document}

$$\left | \int x^2 dx \right |$$

$$\left \lvert \dfrac{x^3+x^2+x+6}{x-9} \right \rvert$$

\end{document}

You may be probably noticing that the \mid command is missing, and that’s because the \left and \right commands don’t work with the \mid command.

Now you have it, all the knowledge you may need to correctly write the absolute value symbols in different ways in your LaTeX document, remember you can always look at the documentation of the packages (amsmath).

I hope this tutorial was helpful in guiding you in LaTeX, and as always keep writing in LaTeX.