Written and maintained by CASRAI Editorial Board
Last updated
In LaTeX, a vertical line is written differently depending on where it appears. In math mode, type | (and \| for a double line). In a table, put | in the column specification, as in \begin{tabular}{ |c|c|c| }. In running text, a bare | does not give a bar; use \textbar. This page gives one decision table for all four contexts, then the details for each.
What it is used for in research
Researchers meet the vertical line in four places: as a symbol in text, as a relation or absolute-value bar in equations, as a rule between columns in a results table, and as an “evaluated at” bar in calculus. LaTeX treats each context differently, so the same keystroke can be right in one place and wrong in another. For horizontal rules, see horizontal lines in LaTeX.
Which command to use, by context
| Context | What to type | Result |
|---|---|---|
| Running text (text mode) | \textbar |
A vertical bar. A bare | in text mode produces an em dash. |
| Math mode, single line | | |
A vertical line |
| Math mode, double line | \| |
A double vertical line |
| Math mode, as a relation | \mid |
A vertical line whose spacing differs from plain | |
| Table column rule | | inside the column spec, e.g. { |c|c|c| } |
A vertical line between columns |
| Table, double column rule | || inside the column spec |
A double vertical line |
| Larger bar in math | \big|, \Big|, \bigg|, \Bigg| |
Progressively taller single bars |
| Evaluated-at bar | \left. … \right|_0^1 |
A bar that scales to the expression, with limits |
The sources for each row are listed at the end of the page.
Where to run the code
These commands are standard LaTeX and work in any LaTeX editor or distribution. The examples follow the documentation published by Overleaf, an online LaTeX editor, so you can paste them into an Overleaf project and compile.
Step by step, by context
How do I write ‘|’ in LaTeX text?
Use \textbar. In text mode, typing | directly produces an em dash rather than a vertical bar, which surprises many people who expect the keyboard character to pass through.
- Write your sentence in normal text, for example
Use the \textbar{} character to separate fields. - Compile. The output contains a vertical bar.
How do I insert a vertical line in a LaTeX equation?
In math mode, | gives a vertical line and \| gives a double vertical line.
- Enter math mode and type the bars, for example
$|x+y|$. - For a double bar, use
$\|x+y\|$. - To make the bars taller, use
\big|,\Big|,\bigg|or\Bigg|for single bars, and\big\|,\Big\|,\bigg\|or\Bigg\|for double bars.
Overleaf’s guide to brackets and parentheses adds a rule for automatic sizing: when you use \left and \right, both commands are mandatory, even if you only want one bracket. For other math layouts where delimiters matter, see matrices in LaTeX and aligned equations in LaTeX.
What is the difference between | and \mid?
Both draw a vertical line in math mode, but their spacing differs. The Wikibooks LaTeX mathematics page lists the delimiter as “| or \mid (difference in spacing)”, and Wikipedia notes that the spacing of the plain bar also differs from \mid and \parallel, which are relation operators.
For a bar between \left and \right that must resize with the expression, Wikibooks shows \middle|, for example P\left(A=2\middle|...\right).
How do I write ‘evaluated at’ with a vertical bar?
Wikibooks shows two forms. An underscore after a bar denotes evaluation: f(n) = n^5 + 4n^2 + 2 |_{n=17}. For a tall bar after a fraction, use a period as an invisible left delimiter: \left.\frac{x^3}{3}\right|_0^1. The \left. supplies the required opening delimiter without drawing anything, so the closing \right| scales to the fraction.
How do I add vertical lines between table columns?
Put | characters in the column specification, as the Overleaf Tables documentation shows. For example, \begin{tabular}{ |c|c|c| } gives three centred columns separated by vertical lines. Use || for a double vertical line.
- Start the table with a column specification that has
|where you want a line:{ |c|c|c| }. - Add horizontal rules with
\hlineat the top and bottom, or\cline{i-j}for a partial rule. - To repeat a column,
*{3}{|l}|is equivalent to|l|l|l|. - To draw a line on each side of a single merged cell, use
\multicolumnwith{|c|}. - To change the line thickness, set
\setlength{\arrayrulewidth}{0.5mm}.
The horizontal side of table rules is covered in horizontal lines in LaTeX.
Output and how to read it
After compiling, check each case against what you intended. A text-mode bar should be a vertical stroke, not a dash. A math-mode bar should match the height of what it encloses; if it looks too short beside a fraction, use the sizing commands or \left and \right. In a table, each | in the column specification becomes one line at that column boundary, and || becomes a double line.
Troubleshooting
- An em dash appears instead of a bar: you typed
|in text mode. Use\textbar. - The bar looks too small: use
\big|through\Bigg|, or\leftand\right, remembering that both of the pair are mandatory. - Spacing around the bar looks wrong: try
\midinstead of|, or the reverse; their spacing differs. - You need a closing bar with no opening one: pair
\right|with\left..
If you are also splitting a formula across lines, see new lines in LaTeX equations.
FAQ
How to write ‘|’ in LaTeX?
In math mode, type |. In text mode, type \textbar, because a bare | produces an em dash there. In a table column specification, | draws a vertical line between columns.
How do I insert a vertical line in LaTeX?
It depends on context: | or \| in math mode, | in a table column spec, \textbar in text. The decision table above lists each.
What is the ‘|’ called?
Wikipedia lists the names pipe, bar, vbar and “or”, and in logic it is the Sheffer stroke. Its Unicode name is VERTICAL LINE (U+007C).
How can you type a vertical line?
Type the | character, then use the context-specific form from the table above so it renders as a bar rather than an em dash or a mis-spaced symbol.
Sources
- Overleaf, Tables (checked 2026-11-07): column specifications,
||,*{3}{|l}|,\multicolumn,\hline,\cline,\arrayrulewidth. - Overleaf, Brackets and Parentheses (checked 2026-11-07): pipes, double pipes, sizing commands, the
\left/\rightrule. - Wikipedia, Vertical bar (checked 2026-11-07): names, Unicode,
\textbar, the text-mode em dash, spacing versus\midand\parallel. - Wikibooks, LaTeX/Mathematics (checked 2026-11-07):
|versus\mid,\middle,\left., evaluation bars.







