LaTeX error · Environments, lists and tables

You can't use `\hrule' here except with leaders.

Quick answer

\hrule is a primitive that draws a rule across a vertical list, between lines. Inside a horizontal context, such as a cell of an l, c or r table column, an \mbox, a \makebox or math, it is not allowed. In tables use \hline (or \midrule from booktabs) at the start of a row, and in running text use \rule{\linewidth}{0.4pt} on its own line.

The error in the log

This is how the message appears in the .log file (and in the compile output). The line starting with l. is the line number where TeX noticed the problem; the real mistake is there or just before it.

! You can't use `\hrule' here except with leaders.
<recently read> \hrule 
                       
l.5   \hrule

Why it happens

  • \hrule used in a tabular to separate rows; in the table it lands inside the first cell of the next row.
  • \hrule inside \mbox, \makebox, \fbox or a header defined with fancyhdr, which are horizontal boxes.
  • \hrule in math mode, for example inside an equation to draw a line.

How to fix it

In a table, replace \hrule with \hline, or with \toprule, \midrule and \bottomrule from booktabs. These must come right after \\ or at the start of the table.

Anywhere else, use \rule{width}{thickness}, which works in horizontal mode, for example \noindent\rule{\linewidth}{0.4pt}.

Broken: reproduces the error

\documentclass{article}
\begin{document}
\begin{tabular}{ll}
  Item  & Price \\
  \hrule
  Apple & 1.20 \\
\end{tabular}
\end{document}

Try this in Octree — free LaTeX editor with AI, compiles in your browser

Fixed: compiles cleanly

\documentclass{article}
\begin{document}
\begin{tabular}{ll}
  Item  & Price \\
  \hline
  Apple & 1.20 \\
\end{tabular}
\end{document}

Related errors

Frequently Asked Questions

What is the difference between \hrule and \rule?

\hrule is a TeX primitive that only works between paragraphs and always spans the full width of the box it is in. \rule{w}{h} is a LaTeX command that makes a box of a given size, so it can be used inside text, cells and boxes.

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

Use \hline after the \\ of a row, or the booktabs rules \toprule, \midrule and \bottomrule. For a line under some columns only, use \cline{2-3} or \cmidrule{2-3}.

What does "except with leaders" mean?

Leaders repeat a box or rule to fill space, as in a dotted table of contents line. TeX allows a rule in that construction only, which is why it mentions leaders. For ordinary documents the fix is \hline or \rule.

Paste your document into Octree — compile errors get a Fix with AI button

When a compile fails, Octree shows the error next to the line that caused it and offers a one-click fix that you can review before applying. Free, nothing to install.

Fix it in Octree →