LaTeX Horizontal Line: 6 Ways in Text and Math
November 11, 2026 · 9 min read
LaTeX Horizontal Line: 6 Ways to Draw Rules in Text and Math
To draw a LaTeX horizontal line across the page, put \noindent\rule{\linewidth}{0.4pt} on its own line between two paragraphs. Use \hrulefill for a line that fills the rest of a text line, and \overline or \underline for lines in math. Every snippet below compiles, and a table near the end shows which ones also render in Markdown math.
The Quick Answer: A Full-Width LaTeX Horizontal Line
Here's the line most people want: a thin divider between two paragraphs, as wide as the text.
The first paragraph ends here.
\noindent\rule{\linewidth}{0.4pt}
The second paragraph starts here.
That produces a 0.4pt line running from the left margin to the right margin, with normal paragraph spacing above and below. The LaTeX2e reference for \rule calls 0.4pt the common line thickness in LaTeX, so it matches the rules your document class already draws.
Two details make it work. \noindent matters because a new paragraph starts with an indent, and the rule gets pushed right by that amount. In our test with the article class, leaving it out made the line overshoot the right margin by 15pt.
\linewidth is the width of the current line, while \textwidth is the width of the whole text block. They're equal in plain body text, but inside a list or a two-column layout \linewidth shrinks to the space you actually have, while \textwidth keeps the full block width. Never use \paperwidth: that's the width of the sheet itself, so the rule runs off the page.
How Do You Add a Horizontal Line With \rule?
\rule draws a filled rectangle. Make it wide and thin and you get a line. The full syntax is \rule[raise]{width}{thickness}, where the optional raise lifts the rule above the baseline (or drops it, if negative).
Short line: \rule{3cm}{0.4pt} and the text carries on.
That gives a 3 cm line sitting on the baseline, in the middle of the sentence. Because \rule is just a box, it flows with the text like a wide letter.
\noindent\rule{\linewidth}{2pt}
Raised: \rule[0.5ex]{2cm}{0.4pt} text.
\begin{center}
\rule{0.5\linewidth}{0.5pt}
\end{center}
The first line is a thick 2pt bar across the text block. The second is a 2 cm line lifted to roughly the middle of the lowercase letters, like a dash. The third is a centered line half the text width. A rule with zero width is invisible but keeps its height, so it works as a strut that props open vertical space.
LaTeX Horizontal Rule With \hrule: How It Differs From \rule
\hrule is a TeX primitive, older than LaTeX itself. It doesn't take braces. It stretches to the width of the box it sits in, which on a normal page means the full text width, and by default it's 0.4pt thick.
Some text above.
\medskip
\hrule
\medskip
Some text below.
\hrule height 2pt
\hrule \vspace{2pt} \hrule
That's a thin line with a little breathing room, then a 2pt bar, then a double rule made from two thin lines 2pt apart. \hrule adds no space of its own, so without \medskip or \vspace the line sits tight against the text. If you drop it into the middle of a paragraph, it ends that paragraph first. Our LaTeX new line guide explains \vspace and the preset skips \smallskip, \medskip and \bigskip.
We prefer \noindent\rule{\linewidth}{...} for almost everything. The width is written out, so you know what you'll get. In our test inside an itemize list, \hrule ignored the list indent and ran back to the left margin, while the \rule version lined up with the item text.
LaTeX Horizontal Line in Text: \hrulefill, \dotfill and Blanks
Some lines belong inside the text itself. Think of a signature field, a blank to fill in, or a heading with rules on both sides. \hrulefill is stretchy space that LaTeX fills with a 0.4pt rule instead of white space, as the reference entry for \hrulefill and \dotfill explains.
Name: \hrulefill
\noindent\hrulefill\ Chapter One\ \hrulefill
Introduction\dotfill 1
Answer: \underline{\hspace{4cm}}
Line one runs from the word Name to the right margin. Line two centers the title with a rule on each side. Two fills in one line share the leftover space equally; they don't stack into two separate lines.
The third line puts a row of dots between the entry and the page number. That's dot leaders, as in a table of contents, not a dotted rule. For a fixed-width answer blank, use \underline{\hspace{4cm}} or simply \rule{4cm}{0.4pt}.
Colored, Dashed and Custom-Length Lines
Every command above draws in the current text color, so color comes from the xcolor package. Wrap the rule in a group so the color doesn't leak into the next paragraph.
\usepackage{xcolor} % in the preamble
\usepackage{tikz} % in the preamble
\noindent{\color{gray}\rule{\linewidth}{1pt}}
\noindent\tikz\draw[dashed] (0,0) -- (8cm,0);
The first line is a 1pt gray rule across the text. The second is an 8 cm dashed line drawn with TikZ, which ships in the pgf package. \rule can't do dashes, so TikZ is the usual route for dashed or dotted rules.
For a line under the running header, the fancyhdr package draws one through its \headrulewidth length, set with \renewcommand{\headrulewidth}{0.4pt} (0pt removes it).
You'll also see \line(1,0){300} in older tutorials. The reference manual documents \line as a picture environment command, so keep it inside \begin{picture} and use \rule everywhere else.
Lines Over and Under Math: \overline, \underline and Array Rules
In math mode, a horizontal line in LaTeX usually sits on top of or under an expression. Use \overline for that, and \underline for the line beneath.
$\overline{AB}$ % line segment AB
$\overline{z}$ % complex conjugate
$0.\overline{3}$ % 0.333... repeating
$\bar{x}$ % short bar accent
$\underline{x+y}$ % line under the sum
\overline spans its whole argument, so \overline{AB} covers both letters. \bar is an accent sized for one character, which suits a mean like \bar{x} but looks too short over two letters. \underline draws its line fully below the text, dropping lower for letters with descenders. For a line through the middle of a word or term, see our LaTeX cross out guide.
To draw a line between two rows of a tabular or array, use \hline (KaTeX's array also accepts \hdashline). Outside those environments, \hline fails with a Misplaced \noalign error. Our guide to building a table in LaTeX covers row rules and the booktabs alternatives.
Which Horizontal Line Commands Render in Markdown Math?
Most Markdown editors render math with KaTeX or MathJax, not a full TeX engine, so only commands that make sense inside a formula work. We checked each command against KaTeX 0.16 and its list of supported functions.
| Command | Real LaTeX | KaTeX (our editor's preview) | Notes |
|---|---|---|---|
\rule | Yes | Yes | Use em, pt or cm. \linewidth gives a parse error |
\rule[raise] | Yes | Yes | The raise argument works too |
\overline, \underline, \bar | Yes | Yes | Same output as LaTeX |
\hline in array | Yes | Yes | Only between rows |
\hdashline in array | Needs the arydshln package | Yes | Dashed row rule |
\hrule | Yes | No | Page-level primitive |
\hrulefill, \dotfill | Yes | No | Text-mode fills |
\line, TikZ | Yes | No | Graphics, not math |
Unsupported commands don't break the page. In our editor's preview, KaTeX shows that formula's source in red so you can spot it. For a plain divider in a Markdown document, skip LaTeX and use ---, as covered in our guide to the Markdown horizontal line.
Here's the KaTeX-safe set, live. Edit the widths and thicknesses and the preview updates as you type.
One limitation: the preview only shows lines that live inside math. A page rule from \hrule or a fill from \hrulefill needs a real TeX compile, so check those in your LaTeX build.
Converting a Markdown Divider to a LaTeX Horizontal Rule
If you write in Markdown and convert to LaTeX later, your --- dividers become \rule commands. Which one depends on the converter.
First section.
---
Second section, with inline math $\overline{AB}$.
Pandoc's LaTeX writer turns that --- into \begin{center}\rule{0.5\linewidth}{0.5pt}\end{center}, a centered line half the text width. Our Markdown to LaTeX converter writes \noindent\rule{\linewidth}{0.4pt} instead, a full-width line, and passes $...$ math through unchanged. It runs in your browser and gives you a .tex file to compile yourself.
For the full Pandoc command line and template options, see Markdown to LaTeX with Pandoc. Still deciding which format to write in? Our Markdown vs LaTeX comparison weighs them up.
A LaTeX horizontal line comes down to picking the right command for where it goes: \rule between paragraphs, \hrulefill inside a line of text, and \overline or \underline in math. Only the math-mode set renders in KaTeX, so test those live in the editor and see our guide to Markdown equations for the delimiters. Convert finished drafts with the Markdown to LaTeX tool.