Horizontal Line in LaTeX: \hrule, \rule, \hrulefill and \noindent
Updated December 1, 2026
Quick answer
- Full-width line:
\noindent\rule{\linewidth}{0.4pt}on its own line between paragraphs. No package needed. - Quickest divider:
\hrule, a TeX primitive that only works between paragraphs. - Line in text:
\rule{3cm}{0.4pt}for a fixed length, or\hrulefill(\dotfillfor dots) to fill the rest of the line. - Tables:
\hlineand\cline{2-3}, or\toprule,\midrule,\bottomrulewith\usepackage{booktabs}. - Why
\noindent: without it the paragraph indent pushes a full-width rule into the right margin (Overfull \hbox).
LaTeX Horizontal Line: \hrule, \rule and \hrulefill
These three commands differ in their allowed contexts and how they set the line length:
| Command | Where it works | Length | Thickness |
|---|---|---|---|
\hrule | Between paragraphs only | Full width, or width 5cm | height 1pt (default 0.4pt) |
\rule{w}{t} | Anywhere, like a word | First argument | Second argument |
\hrulefill | Inside a line of text | Whatever space is left | Fixed at 0.4pt |
\hrule: a line between paragraphs
\hrule is a TeX primitive. It takes no braces; its dimensions are given as optional keywords, and it only works in vertical mode, i.e. between paragraphs. If you type it in the middle of a sentence TeX ends the paragraph first, which is why it sometimes appears to add a blank line:
Some text before the line.
\hrule % 0.4pt thick, full column width
\hrule height 1pt % thicker
\hrule height 0.4pt width 5cm % shorter (left aligned)
Some text after the line.Because \hrule lives outside paragraphs, it cannot be centred and does not respond to \centering. For anything but a quick full-width divider, use \rule.
\rule: a line inside text
\rule[raise]{width}{thickness} is the LaTeX command. It produces a box, so it behaves like a word: it sits on the baseline, it can be centred, colored and placed inside a table cell. A full-width line needs \noindent, otherwise the paragraph indent pushes it past the margin and you get an Overfull \hbox warning:
\noindent\rule{\linewidth}{0.4pt} % full width, standard thickness
\noindent\rule{\textwidth}{1pt} % thicker
\rule{3cm}{0.4pt} % short, inline
\rule[0.5ex]{2cm}{0.4pt} % raised half an x-height\linewidth is the width of the current line, which shrinks inside lists, quotes and minipages; \textwidth stays at the document text width inside a list, but is reset to the local width inside a minipage. In a two-column document, \columnwidth is the width of one column. The optional first argument raises the rule above the baseline (negative values lower it).
\hrulefill and \dotfill: fill the rest of the line
\hrulefill is stretchable glue drawn as a line. It fills whatever space is left on the line, which makes it the right tool for forms, tables of contents and “Name: ____” fields. \dotfill does the same with dots:
Name: \hrulefill
Date: \hrulefill\quad Signature: \hrulefill
Chapter One \dotfill 1
\noindent\hrulefill % equivalent to a full-width rule\hrulefill is always 0.4pt thick. For a thicker fill define a variant with \leaders:
\newcommand{\thickhrulefill}{%
\leavevmode\leaders\hrule height 1pt\hfill\kern0pt
}
Total: \thickhrulefill\noindent and Full-Width Lines
A full-width rule is exactly as wide as the line, so any indent makes it too wide. Every new paragraph is indented by \parindent (about 15pt in the standard classes), which is why a bare \rule{\linewidth}{0.4pt} ends up shifted right and overflowing the margin. \noindent at the start of the paragraph cancels the indent:
\documentclass{article}
\begin{document}
Text before.
\rule{\linewidth}{0.4pt} % wrong: indented, runs into the margin
\noindent\rule{\linewidth}{0.4pt} % right: starts at the left margin
\begin{itemize}
\item An item with a line that respects the list indent:\par
\noindent\rule{\linewidth}{0.4pt}
\end{itemize}
\end{document}Use \linewidth rather than \textwidth for the width. Inside a list or quote, \linewidth shrinks to the current line while \textwidth stays at the document text width, so a \textwidth rule pokes out on the right. A minipage resets both widths; a list nested inside that minipage narrows only \linewidth again.\hrule is not affected by the paragraph indent, but \hrulefill at the start of a paragraph begins after it, so a full-width fill also needs \noindent.
A divider inside a narrow panel
Use the same command at each nesting level rather than hard-coding the outer page width. This complete example draws one divider across the panel and another across the narrower list item. End the rule paragraph explicitly so the following text cannot join it and overflow the line.
\documentclass{article}
\begin{document}
\noindent\begin{minipage}{0.6\linewidth}
Panel heading
\par\noindent\rule{\linewidth}{0.4pt}\par
\begin{itemize}
\item A narrower divider follows this item.
\par\noindent\rule{\linewidth}{0.4pt}\par
Text below the divider stays inside the item.
\end{itemize}
\end{minipage}
\end{document}Horizontal Line in Text
For a horizontal line in text, inside a sentence rather than between paragraphs, use \rule or \hrulefill. Both stay in the paragraph. The optional first argument of \rule raises it from the baseline, which is how you draw a line at the height of a dash or through the middle of the letters:
\documentclass{article}
\begin{document}
Fill in the blank: the capital of France is \rule{3cm}{0.4pt}.
A line at mid-height \rule[0.5ex]{2cm}{0.4pt} between two words.
Name: \hrulefill
Total \dotfill 42
% a line that fills a fixed-width gap
Answer: \makebox[4cm]{\hrulefill} (in words)
\end{document}Do not use \hrule here. It is a vertical-mode command, so TeX ends the current paragraph, draws the line on its own and starts a new paragraph after it. That is the usual cause of a “line that jumps to the next line”.
Partial-Width and Centred Lines
A line that spans half the text width is just \rule with a fraction. To centre it, put it in a center environment or use \centerline, which adds no vertical space (it must sit between paragraphs, so leave a blank line before it):
\begin{center}
\rule{0.5\linewidth}{0.4pt}
\end{center}
% or, with no extra space above and below:
\centerline{\rule{0.5\linewidth}{0.4pt}}
% right-aligned
\begin{flushright}
\rule{4cm}{0.4pt}
\end{flushright}A short centred rule is the traditional way to mark a scene break in fiction; a common definition is:
\newcommand{\scenebreak}{%
\par\medskip\centerline{\rule{0.3\linewidth}{0.4pt}}\medskip
}
The door closed behind her.
\scenebreak
Three weeks later, the letter arrived.Space Above and Below a Line
A rule in its own paragraph picks up the normal paragraph spacing, which is often not what you want. Control it explicitly with \vspace or the skip commands:
\vspace{1em}
\noindent\rule{\linewidth}{0.4pt}
\vspace{1em}
% compact form with explicit paragraph boundaries
\par\medskip\noindent\rule{\linewidth}{0.4pt}\par\medskip\smallskip, \medskip and \bigskip insert roughly 3pt, 6pt and 12pt of stretchable space. For a reusable divider, wrap the whole thing in a \newcommand so every instance is spaced identically. These skips still interact with \parskip and normal line spacing; they are not a promise of an exact gap. Unstarred \vspace can also disappear at a page boundary. Use \vspace* only when that space must remain at the top of a page.
Colored Lines
A \rule is drawn in the current text color, so any xcolor command works. Keep the color change inside a group so it does not leak into the following text:
\usepackage{xcolor}
\noindent{\color{gray}\rule{\linewidth}{0.4pt}}
\noindent\textcolor{blue!60}{\rule{\linewidth}{1pt}}
Total: {\color{red}\hrulefill} % \hrulefill takes the color tooHorizontal Lines in Tables: \hline and \midrule
Inside tabular, horizontal lines are not drawn with \rule but with dedicated row commands. The standard ones are \hline for a line across the whole table and \cline{i-j} for a line under columns i to j. Both must appear at the start of a row, i.e. right after \\ or immediately after \begin{tabular}{...}:
\begin{tabular}{lcc}
\hline\hline % double line
Item & 2025 & 2026 \\
\hline
Apples & 12 & 15 \\
Pears & 8 & 11 \\
\cline{2-3} % line under the two number columns only
Total & 20 & 26 \\
\hline
\end{tabular}The thickness of every \hline is the length \arrayrulewidth (default 0.4pt): \setlength{\arrayrulewidth}{1pt} makes them all heavier.
booktabs: \toprule, \midrule, \bottomrule
For publication tables load booktabs. Its three rules have different thicknesses and, more importantly, built-in vertical padding, which is what makes a table look professionally typeset:
\usepackage{booktabs}
\begin{tabular}{lrr}
\toprule
Method & Accuracy & Time (s) \\
\midrule
Baseline & 91.2 & 14 \\
Ours & 94.7 & 9 \\
\cmidrule(lr){2-3} % partial rule, trimmed on both sides
Mean & 93.0 & 11.5 \\
\bottomrule
\end{tabular}Do not mix \hline into a booktabs table. \hline has no padding, so the text sits directly on the line and the spacing becomes uneven compared with the booktabs rules around it; the package documentation also advises against vertical lines and double rules for the same reason. If you need a rule with custom thickness and spacing, use \specialrule{thickness}{space above}{space below}, and use \addlinespace for a little extra air between rows without a line. The thicknesses are the lengths \heavyrulewidth (0.08em) and \lightrulewidth (0.05em).
Lines in Headers and Footers
With fancyhdr the header rule is on by default and the footer rule is off. Both are controlled by two commands (not lengths, so use \renewcommand):
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{\leftmark}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.4pt} % 0pt removes the header rule
\renewcommand{\footrulewidth}{0.4pt} % add a footer rule
% colored header rule
\usepackage{xcolor}
\renewcommand{\headrule}{{\color{gray}%
\hrule height\headrulewidth width\headwidth \vskip-\headrulewidth}}Signature and Form Lines
A signature line is a rule of fixed width with a label underneath. Leave room above it for the pen, and use a tabular to keep several lines aligned:
\vspace{2cm}
\noindent\rule{6cm}{0.4pt}\\
Signature
% two signature lines side by side with labels
\vspace{2cm}
\noindent
\begin{tabular}{@{}p{6cm}@{\hspace{1.5cm}}p{4cm}@{}}
\rule{6cm}{0.4pt} & \rule{4cm}{0.4pt} \\
Signature & Date
\end{tabular}
% a line that fills a fixed-width box
Name: \makebox[6cm]{\hrulefill}Keep a divider with the text it introduces
A rule is not a heading: LaTeX does not automatically keep it beside the next paragraph. At a page boundary, a divider can remain at the bottom while its explanation moves to the next page. Reserve space before the divider with \Needspace, then prohibit the immediate break after it. This is preferable to adding a manual page break, which becomes wrong as earlier text changes.
\documentclass{article}
\usepackage{needspace}
\begin{document}
Text before the next topic.\par
\Needspace{4\baselineskip}
\noindent\rule{\linewidth}{0.4pt}\par
\nopagebreak
\noindent The next topic begins here and stays with its divider.
The reserved space allows room for several lines of explanation.
\end{document}The reservation is a minimum, not a fixed-height box. Increase it if the following heading or opening paragraph needs more room. Keep this pattern in normal document flow: a minipage cannot split across pages, so a page-space check inside one does not solve an oversized panel. For repeated section dividers, configure the heading style instead of inserting unrelated rules throughout the document.
Test both a short page and a nearly full page. If the line belongs to the text above, rather than the text below, the break constraint belongs before the rule instead. Placement is a semantic choice: a signature rule, a section separator and a table rule may look similar but should not share one layout recipe.
Common Errors
| Message or symptom | Cause | Fix |
|---|---|---|
| Misplaced \noalign | \hline, \cline or \midrule in the middle of a row (after a cell, or before the \\ that ends the previous row) | End the row with \\ first; the rule command must be the very first thing in a row |
| Line sticks out into the right margin, Overfull \hbox | \rule{\linewidth}{...} after a paragraph indent | Add \noindent before the rule |
| Line appears on its own line although it was meant inline | \hrule used inside a paragraph | Use \rule or \hrulefill in running text |
| Uneven spacing around rules in a booktabs table | \hline mixed with \toprule/\midrule | Use only the booktabs rules, \cmidrule and \specialrule |
| Line is too long inside a list or quote | Width given as \textwidth | Use \linewidth, which follows the current indentation |
\hrule stays left-aligned inside center | \hrule is not a box, so alignment environments do not affect it | Use \centerline{\rule{0.5\linewidth}{0.4pt}} |
| Undefined control sequence \toprule | booktabs not loaded | \usepackage{booktabs} |
Complete Example
\documentclass{article}
\usepackage[margin=2.5cm, headheight=15pt]{geometry}
\usepackage{xcolor}
\usepackage{booktabs}
\usepackage{dashrule}
\usepackage{fancyhdr}
\usepackage{titlesec}
% header rule only, in gray
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{Horizontal Lines}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\headrule}{{\color{gray}%
\hrule height\headrulewidth width\headwidth \vskip-\headrulewidth}}
% rule under every section title
\titleformat{\section}{\normalfont\Large\bfseries}{\thesection}{1em}{}[\titlerule]
% reusable divider with fixed spacing
\newcommand{\divider}{\par\medskip\noindent\rule{\linewidth}{0.4pt}\par\medskip}
\begin{document}
\section{Rules in Text}
A full-width line separates this paragraph from the next.
\divider
A short centred rule marks a scene break.
\centerline{\rule{0.3\linewidth}{0.4pt}}
A colored dashed rule:
\par\noindent{\color{blue!60}\hdashrule{\linewidth}{0.6pt}{3mm 1mm}}
\section{Rules in a Table}
\begin{center}
\begin{tabular}{lrr}
\toprule
Method & Accuracy & Time (s) \\
\midrule
Baseline & 91.2 & 14 \\
Ours & 94.7 & 9 \\
\cmidrule(lr){2-3}
Mean & 93.0 & 11.5 \\
\bottomrule
\end{tabular}
\end{center}
\section{Signature}
\vspace{1.5cm}
\noindent
\begin{tabular}{@{}p{6cm}@{\hspace{1.5cm}}p{4cm}@{}}
\rule{6cm}{0.4pt} & \rule{4cm}{0.4pt} \\
Signature & Date
\end{tabular}
\end{document}Frequently Asked Questions
How do I draw a full-width horizontal line in LaTeX?
Use \par\noindent\rule{\linewidth}{0.4pt}\par. It needs no package, respects the current line width, and ends the paragraph so following text cannot overflow beside the rule.
Why does my horizontal line overflow a list or panel?
Use \linewidth, not the outer \textwidth, and remove paragraph indentation with \noindent. A list inside a minipage narrows the available line width again.
How do I keep a divider with the next paragraph?
Reserve space with \Needspace from needspace before the divider, then use \nopagebreak after its paragraph. Test near a page boundary; an unbreakable minipage needs a different layout.
Can I use hline outside a table?
No. Use \rule or \hrule for text dividers. Use \hline at a row boundary in tabular, or booktabs rules for a table with deliberate spacing.
Next Steps
Lines in place? These guides pick up where this one stops:
- LaTeX Tables – booktabs, multicolumn, multirow, longtable and colored tables
- Blank Spaces and Line Breaks in LaTeX –
\vspace,\\,\newlineand the spacing around your rules - LaTeX Page Numbering – fancyhdr headers and footers, page styles and numbering
- Using Colors in LaTeX – The xcolor names and mixes used for colored rules
Documentation and a place to test
Consult the needspace documentation and booktabs documentation for supported options. Test a complete example in LaTeX Preview, then check the PDF with your final document class.
Fix layout problems faster with AI
Open the complete example in Octree, change a rule's width, and compare the PDF. If your own layout overflows, ask the AI assistant to explain the warning before applying a fix.
Open Octree →