Horizontal Line in LaTeX: \hrule, \rule, \hrulefill and \noindent

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 (\dotfill for dots) to fill the rest of the line.
  • Tables: \hline and \cline{2-3}, or \toprule, \midrule, \bottomrule with \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:

CommandWhere it worksLengthThickness
\hruleBetween paragraphs onlyFull width, or width 5cmheight 1pt (default 0.4pt)
\rule{w}{t}Anywhere, like a wordFirst argumentSecond argument
\hrulefillInside a line of textWhatever space is leftFixed 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 too

Dashed 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, short

With 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);

Horizontal 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}}

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

Message or symptomCauseFix
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 indentAdd \noindent before the rule
Line appears on its own line although it was meant inline\hrule used inside a paragraphUse \rule or \hrulefill in running text
Uneven spacing around rules in a booktabs table\hline mixed with \toprule/\midruleUse only the booktabs rules, \cmidrule and \specialrule
Line is too long inside a list or quoteWidth given as \textwidthUse \linewidth, which follows the current indentation
\hrule stays left-aligned inside center\hrule is not a box, so alignment environments do not affect itUse \centerline{\rule{0.5\linewidth}{0.4pt}}
Undefined control sequence \toprulebooktabs 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 you draw a horizontal line in LaTeX?

Put \noindent\rule{\linewidth}{0.4pt} on its own line between two paragraphs. It draws a 0.4pt line across the full text width and needs no package. \hrule does the same in one word, and \hrulefill fills only the rest of the current line.

How do I put a horizontal line in text, in the middle of a sentence?

Use \rule{3cm}{0.4pt} for a line of fixed length or \hrulefill for a line that stretches to the end of the line, as in Name: \hrulefill. Both stay inside the paragraph. Do not use \hrule there: it ends the paragraph and puts the line on a line of its own.

Why do I need \noindent before \rule?

A new paragraph starts with an indent, usually 15pt. \rule{\linewidth}{0.4pt} is already as wide as the line, so the indent pushes it past the right margin and LaTeX reports an Overfull \hbox. \noindent removes the indent so the line starts at the left margin.

What is the difference between \hrule, \rule and \hrulefill?

\hrule is a TeX primitive that only works between paragraphs and always spans the full width unless you give it a width. \rule{width}{thickness} is a box that behaves like a word, so it can be centred, colored or placed inline. \hrulefill is stretchable space drawn as a line that fills whatever room is left on the current line.

How do I make a thicker horizontal line in LaTeX?

Change the second argument of \rule: \noindent\rule{\linewidth}{1pt} draws a 1pt line. With \hrule write \hrule height 1pt. In tables, \setlength{\arrayrulewidth}{1pt} thickens every \hline, and booktabs takes a thickness in brackets, as in \midrule[1pt].

How do I add a horizontal line in a LaTeX table?

Write \hline at the start of a row for a line across the whole table and \cline{2-3} for a line under columns 2 to 3. For publication tables load booktabs and use \toprule, \midrule and \bottomrule, which add padding around the line. A rule placed in the middle of a row causes the Misplaced \noalign error.

Next Steps

Lines in place? These guides pick up where this one stops:

Free LaTeX Tools

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.

Try Octree Free →