Horizontal Lines in LaTeX: \hrule, \rule, \hrulefill and Table Rules
A horizontal line in LaTeX is drawn with one of three commands, and which one you need depends on where the line goes. \hrule is the TeX primitive for a line between paragraphs, \rule draws a line of any width and thickness inside text, and \hrulefill stretches a line to fill the rest of a line. This guide covers all three, plus partial and centred lines, colored and dashed lines, rules in tables with booktabs, header and footer rules with fancyhdr, rules under section titles, signature lines and the Misplaced \noalign error.
The Three Line Commands
\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 is always the full text block. 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
}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
}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 that does not depend on \parskip
\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.
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 tooDashed and Dotted Lines
Plain LaTeX has \dotfill and nothing else. For a real dashed rule use the dashrule package, whose \hdashrule has the same arguments as \rule plus a dash pattern of alternating on/off lengths:
\usepackage{dashrule}
\noindent\hdashrule{\linewidth}{0.4pt}{1pt} % 1pt dash, 1pt gap
\noindent\hdashrule{\linewidth}{0.4pt}{3mm 1mm} % 3mm dash, 1mm gap
\hdashrule[0.5ex]{4cm}{1pt}{2pt} % raised, shortWith TikZ you get full control over the dash pattern, line caps and color:
\usepackage{tikz}
\noindent\begin{tikzpicture}
\draw[dashed] (0,0) -- (\linewidth,0);
\end{tikzpicture}
\noindent\tikz\draw[dotted, thick, gray] (0,0) -- (\linewidth,0);
\noindent\tikz\draw[dash pattern=on 6pt off 2pt, line width=0.8pt] (0,0) -- (\linewidth,0);Lines in Tables
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}}Lines Under Section Titles
The titlesec package formats headings, and its \titlerule draws a rule the full width of the heading. Give it as the optional “after code” argument of \titleformat:
\usepackage{titlesec}
\titleformat{\section}
{\normalfont\Large\bfseries} % format of the whole title
{\thesection} % label
{1em} % space between label and title
{} % code before the title
[\titlerule] % code after: a rule under the title
% thicker rule, or a dotted one
\titleformat{\section}{\Large\bfseries}{\thesection}{1em}{}[{\titlerule[1pt]}]
\titleformat{\section}{\Large\bfseries}{\thesection}{1em}{}[{\titlerule*[0.5pc]{.}}]Without titlesec, the quick way is \section{Title}\vspace{-1ex}\noindent\rule{\linewidth}{0.4pt} wrapped in a helper command, but it does not survive page breaks as gracefully.
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}Aside: Vertical Rules
The vertical counterparts behave the same way. \vrule is the primitive for horizontal mode (it stretches to the height of the enclosing line or box), and \rule with a small width and a large height gives a vertical bar of fixed size. In tables, a | in the column specification draws a vertical rule between columns:
left \vrule\ right % bar as tall as the line
left \rule{0.4pt}{1cm} right % 1cm bar standing on the baseline
left \rule[-0.4cm]{0.4pt}{1cm} right % lowered so it straddles the baseline
\begin{tabular}{|l|c|} % vertical rules between columns
\hline
a & b \\
\hline
\end{tabular}Common Errors and Fixes
| 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}Quick Reference
| Task | Command |
|---|---|
| Full-width line between paragraphs | \hrule or \noindent\rule{\linewidth}{0.4pt} |
| Thicker line | \noindent\rule{\linewidth}{1pt} |
| Short line, inline | \rule{3cm}{0.4pt} |
| Raised line | \rule[0.5ex]{3cm}{0.4pt} |
| Fill the rest of the line | \hrulefill / \dotfill |
| Centred half-width line | \centerline{\rule{0.5\linewidth}{0.4pt}} |
| Colored line | {\color{gray}\rule{\linewidth}{0.4pt}} (xcolor) |
| Dashed line | \hdashrule{\linewidth}{0.4pt}{3mm 1mm} (dashrule) |
| Dashed line with TikZ | \tikz\draw[dashed] (0,0) -- (\linewidth,0); |
| Table line, full / partial | \hline / \cline{2-3} |
| Booktabs rules | \toprule, \midrule, \cmidrule(lr){2-3}, \bottomrule |
| Table rule thickness | \setlength{\arrayrulewidth}{1pt} |
| Header / footer rule (fancyhdr) | \renewcommand{\headrulewidth}{0.4pt} / \renewcommand{\footrulewidth}{0.4pt} |
| Rule under section titles | \titleformat{\section}{...}{\thesection}{1em}{}[\titlerule] (titlesec) |
| Signature line | \rule{6cm}{0.4pt} |
| Vertical bar | \vrule or \rule{0.4pt}{1cm} |
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
- Learn TikZ – Draw lines, arrows and diagrams programmatically
- Learn LaTeX – Complete beginner tutorial covering all the basics
Free LaTeX Tools
- LaTeX Preview – Test rules and spacing with a live PDF preview
- Excel to LaTeX – Convert spreadsheets to booktabs tables
- LaTeX Symbols Reference – Browse math operators and special characters
Fix layout problems faster with AI
Octree's AI editor explains Misplaced \noalign and overfull box warnings in plain language, fixes your tables, and compiles your document in seconds.
Try Octree Free →