How to Write a Vertical Bar in LaTeX

In LaTeX, you can write a vertical bar using the \textbar{} command.

For mathematical expressions, you can also use the \vert command for a single vertical bar and \| for a double vertical bar.

The following examples show how to write a vertical bar in LaTeX.

How to Write a Vertical Bar in Text

We can use the \textbar{} command in LaTeX document to display vertical bar in a text.

Example: Vertical Bar in Text

Suppose we want to write a vertical bar in the text.

We can use the following LaTeX code to do so:

\documentclass{article}
\begin{document}

This is an example of using a vertical bar \textbar{} in a sentence.

\end{document}

Output: 👇️

This is an example of using a vertical bar | in a sentence.

In this example, the vertical bar is used as a separator in the text.

How to Write a Vertical Bar in Mathematical Expressions

For mathematical expressions, we can use the \textbar{} or the \vert command for a single vertical bar.

For double vertical bars, use the \| command.

Example: Vertical Bar in Mathematical Expressions

Suppose we would like to write mathematical expressions that contain a vertical bar.

We can use the following LaTeX code to do so:

\documentclass{article}
\begin{document}

Aan inline mathematical expression: \( |a + b| \).

A displayed mathematical expression:
\[
\left| \frac{a}{b} \right| + \left| \frac{c}{d} \right|
\]

An inline mathematical expression with \textbackslash vert: \( \vert a + b \vert \).

A displayed mathematical expression with \textbackslash vert:
\[
\left\vert \frac{a}{b} \right\vert + \left\vert \frac{c}{d} \right\vert
\]

An inline mathematical expression with double vertical bars: \( \|a + b\| \).

A displayed mathematical expression with double vertical bars:
\[
\left\| \frac{a}{b} \right\| + \left\| \frac{c}{d} \right\|
\]

\end{document}

Output: 👇️

Vertical Bar in Mathematical Expressions

In this example, we use the vertical bar to denote absolute values and norms in both inline and displayed mathematical expressions.

The \left| and \right| commands are used to adjust the size of the vertical bars to fit the enclosed fractions.

Conclusion

We can use the \textbar{} for both text and mathematical expressions.

For mathematical expressions, the \vert command provides an alternative for a single vertical bar, and the \| commandfor double vertical bars.

For larger expressions, the \left| and \right| commands help in adjusting the size of the vertical bars automatically.