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

absolute value symbol in LaTeX
Absolute value symbol

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}

absolute value symbol in LaTeX
\mid output

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 symbol in LaTeX
“|” output has no space between the lines and the argument

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}

absolute value symbol in LaTeX
Left and right vertical bars output

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

absolute value symbol in LaTeX
Not resizable vertical bars

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}

absolute value symbol in LaTeX
Resizable vertical bars

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. 


Further Reading

LaTex Tutorial on Symbols

  1. How To Create A Cross Product Symbol In LaTeX
  2. How to create a hat symbol in LaTeX?
  3. How to create a prime symbol in LaTeX?
  4. How to create an approximate symbol in LaTeX?
  5. How to create an intersection symbol in LaTeX?
  6. How to create the empty set symbol in LaTeX?
  7. How to write a degree symbol in LaTeX?
  8. How to write a dot product in LaTeX?
  9. How to Write a Greater Than Symbol in LaTeX?
  10. How to write a norm symbol in LaTeX?
  11. How to write A Plus-Minus Symbol in LaTeX
  12. How to write a proportional to symbol in LaTeX?
  13. How to write a real number symbol in LaTeX?
  14. How to write a tilde symbol in LaTeX?
  15. How to write a union symbol in LaTeX?
  16. How to write a vector in LaTeX?
  17. How to write an infinity symbol in LaTeX?
  18. How to write bold text in LaTeX?
  19. How To Write Dots Symbols In LaTeX?
  20. How to write the arrow symbols in LaTeX
  21. How to write the Degree celsius symbol in LaTeX?
  22. How to write the equal or not equal symbol in LaTeX?
  23. How to write the Euro symbol in LaTeX?
  24. How to write the floor symbol in LaTeX?
  25. How to write the gradient operator symbol in LaTeX
  26. How To Write The Greater Than Or Equal To Symbol In LaTeX?
  27. How to write the integer number symbol in LaTeX?
  28. How to write the less than symbol in LaTeX?
  29. How to write the Natural numbers symbol in LaTeX?
  30. How to write the parallel symbol in LaTeX?
  31. How to write the percent symbol in LaTeX?
  32. How to write the square root symbol in LaTeX?
  33. How To Write The Symbol For A Subset In LaTeX?
  34. How to write the symbol for therefore in LaTeX?
  35. How to write with the mathbb in LaTeX?

Photo of author
Author
SJ Tsai
Chief Editor. Writer wrangler. Research guru. Three years at scijournal. Hails from a family with five PhDs. When not shaping content, creates art. Peek at the collection on Etsy. For thoughts and updates, hit up Twitter.

Leave a Comment