tabular basics

The & you type in a table is not an ampersand as far as LaTeX is concerned. It is a character with a special category code — number 4, which TeX calls the alignment tab. That is why getting the column count wrong produces ! Extra alignment tab has been changed to \cr., an error phrased in a word that appears nowhere on your screen. This page walks through the three conventions of the tabular environment — separate cells with &, close a row with \\, draw a rule with \hline — together with the machinery underneath. Once that machinery is visible, the two errors every beginner meets, Extra alignment tab and Misplaced \noalign, stop being riddles and start being instructions.

The three symbols of tabular: &, \\ and \hline

Only three symbols carry meaning inside the body of a tabular. & separates cells within a row, \\ closes a row, and \hline draws one horizontal rule across the full width of the table at that point. \begin{tabular} then takes a mandatory argument, the column specification, immediately after it. \begin{tabular}{ccc} declares “three centred columns”, and the number of columns fixed there is the skeleton of the whole table. Spaces around & are ignored, so you are free to pad them in the source to line the cells up.

latex
\begin{tabular}{ccc}
  \hline
  A & B & C \\
  D & E & F \\
  \hline
\end{tabular}

\\ is not a table-specific symbol but LaTeX’s general line-break command. The same symbol acts as the row separator in pmatrix and in align, so the habit of “align columns with &, break rows with \\” carries straight over from tables to mathematics. The \\ after the final row may be omitted, but if you want a rule beneath that row you must close it with \\ first and only then write \hline — omit it and you walk straight into the Misplaced \noalign covered later on this page. \\ also takes an optional argument in brackets: \\[2pt] adds extra vertical space below that row, and a negative value tightens it.

\begin{tabular} also takes an optional vertical-position argument in brackets before the column spec. \begin{tabular}[t]{…} aligns the top of the table with the baseline of the surrounding line, [b] the bottom; the default aligns the vertical centre. There is a trap here, though: if the table begins or ends with \hline, the alignment happens at the rule and the result is not what you expected. The array package exists partly for this symptom and supplies \firsthline and \lasthline — write those instead of \hline and the table lines up on its first or last row of text.

Extra alignment tab has been changed to \cr — the column count is wrong

This error means one thing only: there are more & in the row than the column spec declared. Write A & B & C in a table declared {ll} and you will always see it. TeX recovers by reading the surplus & as an end-of-row (\cr) and carrying on, so nothing disappears — you get a misaligned table instead of no table. Miscounting the spec is the usual cause, but three subtler ones are common: writing & in a row where \multicolumn{3}{c}{…} has already consumed all three columns; typing \\ inside a cell; and attaching array’s >{\raggedright} to the last column. The last one bites because \raggedright redefines \\, so the row terminator stops working and the next row’s & overflows into the same error — >{\raggedright\arraybackslash} fixes it.

Having too few &, by contrast, is silent. Missing cells are simply set empty, with neither an error nor a warning, so when a table is visibly misaligned yet compiles cleanly, suspect a forgotten & first. One more diagnostic: if you write an unknown letter in the column spec, the wording of the error depends on which package is loaded. Plain LaTeX says ! LaTeX Error: Illegal character in array arg., while with array loaded you get ! Package array Error: Illegal pream-token. Which of the two appears tells you which implementation your table is actually running on.

Misplaced \noalign — \hline only fits between rows

This error is nearly always caused by one thing: writing \hline without having closed the row with \\. Drop the \\ after the last row and follow it with \hline, and the TeX Live 2024 log shows three errors in a chain — ! Misplaced \noalign., ! You can't use \hrule here except with leaders., and ! Missing number, treated as zero.. All three come from the same single cause. The reason lies in the definition of \hline itself: open latex.ltx and you find \def\hline{\noalign{…\hrule \@height \arrayrulewidth …}}. \noalign is a TeX primitive that means only “insert this material between the rows of an alignment”. Called mid-row it has nowhere to go, so \noalign and then its intended contents, \hrule, spill out one after another.

latex
% WRONG: the last row was never closed, so \hline has no gap to sit in
\begin{tabular}{ll}
  A & B \\
  C & D
  \hline
\end{tabular}

% RIGHT: close the row first, then draw the rule
\begin{tabular}{ll}
  A & B \\
  C & D \\
  \hline
\end{tabular}

By the same logic, \hline written inside a cell produces the identical trio of errors. Conversely, \hline standing alone right after a \\ is always safe, and even \hline \\, which creates an empty row, is not an error — it just adds visible space. One more that shows up constantly around tabular is ! LaTeX Error: \caption outside float., the classic result of putting \caption inside a tabular: as the next section explains, the heading is the job of table. Forgetting \end{tabular} produces the more helpful ! LaTeX Error: \begin{tabular} on input line N ended by \end{document}., which even hands you the line number.

Drawing rules, and the rules not to draw

Horizontal rules come from \hline; vertical rules come from writing | into the column spec. {|l|c|r|} puts lines at the outer edges and between all three columns, and with \hline it turns every cell into a box in a grid. \hline\hline gives a double rule, the gap between the two being the length \doublerulesep (2pt by default). Rule thickness is the length \arrayrulewidth, 0.4pt in the standard classes. \cline{2-3} takes a range of column numbers and rules only part of the way across. That is the complete set of rules standard LaTeX can draw.

NotationWhat it doesNotes
&Separates cells in a rowCategory code 4; too many gives Extra alignment tab
\\Closes a rowSame role in align and pmatrix
\\[2pt]Adds vertical space below the rowA negative value tightens it
\hlineFull-width horizontal ruleThickness is \arrayrulewidth (0.4pt)
\hline\hlineDouble horizontal ruleGap is \doublerulesep (2pt)
\cline{2-3}Rules columns 2 to 3 onlyThe idiom for ruling under merged cells
|Vertical rule, written in the column specBest avoided in formal tables
||Double vertical ruleThe gap is again \doublerulesep

Yet of the tools just listed, professional typesetting holds that vertical rules and double rules should not be used at all. The manual for booktabs, Publication quality tables in LaTeX by Simon Fear (the copy in TeX Live 2024 is revised 12 January 2020), states two guidelines: “1. Never, ever use vertical rules. 2. Never use double rules.” The author goes as far as to say that if the left half of a table differs so much from the right that a line seems needed between them, you should use two tables instead — and adds honestly that he once worked for a publisher who insisted on a double light rule above a row of totals, “but this would not have been my choice.” What he recommends instead is horizontal rules of differing thickness with generous space above and below them.

What matters is that these guidelines do not apply to every table. Fear draws an explicit line between a formal table — a set of values in labelled columns — and a tableau, the one-off layout that will probably be strewn with icons and use colour too, and he is clear that the two guidelines are about the former. The layout of a formal table, he writes, was established over centuries of experience and should be altered only in extraordinary circumstances. Read the other way: putting a grid around a schedule or a UI diagram is simply not what the guidelines are about. If you are putting a table of numbers in a paper, the modern idiom is booktabs with \toprule, \midrule and \bottomrule, covered in detail on “Rules and publication-quality tables”.

When rows feel cramped and the rules seem to touch the letters, the quickest remedy is to raise the row-height multiplier with \renewcommand{\arraystretch}{1.2} (the default is 1). The gap between columns is the length \tabcolsep, 6pt on each side by default, so 12pt in total between two columns. If the array package is loaded you also have \setlength{\extrarowheight}{2pt}, which adds to the height of every row while leaving the depth alone — exactly the right cure for rules that graze the tops of capital letters.

tabular vs table: a table is not a float

tabular sets the contents of a table and nothing else: no number, no caption, no say in placement. It is handled like a piece of text, so it can sit mid-paragraph, inside a list item, even inside a footnote. table, by contrast, is a float. You wrap it around a tabular, and it supplies an automatically numbered heading via \caption{…}, cross-references via \label{…} and \ref{…}, and placement specifiers such as [htbp]. Writing \caption inside a tabular gives ! LaTeX Error: \caption outside float. — that division of labour turned into an error message.

document.tex
\begin{table}[htbp]
  \centering
  \caption{Quarterly sales}
  \label{tab:sales}
  \begin{tabular}{lrr}
    \hline
    Quarter & Sales & YoY \\
    \hline
    Q1 & 1{,}200 & +5\% \\
    Q2 & 1{,}350 & +8\% \\
    \hline
  \end{tabular}
\end{table}

% ... and refer to it from the running text:
See Table~\ref{tab:sales}.

The reason for making it a float is less the numbering than the fact that a tabular cannot break across pages. It is set as one large box, so if it does not fit in what remains of the page it is pushed whole onto the next one, leaving a gap behind it. Put inside a table, that box can be moved by LaTeX to the top of a later page and the gap filled with text. [htbp] is a wish-list — here, top of a page, bottom of a page, a page of its own — and LaTeX tries the positions in that order. A table too tall to fit on any single page cannot be a float at all; that is the job of longtable, which does break across pages.

A table with long text: without p{width} it runs off the page

The three specifiers l, c, and r only widen the column to its natural content; they never wrap within the line. Put a long description straight into an l column and the column stretches to the width of that one line, pushing the table off the text block. What you get is the warning Overfull \hbox (…pt too wide) — a warning, not an error, so the document still compiles and you find out only when you look at the PDF. That is what makes this failure annoying. If you need wrapping, plain tabular offers exactly one specifier: p{width}. It sets the cell as a paragraph box of the given width, and content beyond that width flows onto further lines automatically.

latex
\begin{tabular}{l p{5cm} r}
  \hline
  Item & Description & Price \\
  \hline\hline
  Apple  & A large honey-cored variety, popular as a gift. & 380 \\
  Orange & A small, sweet citrus that peels by hand.       & 120 \\
  \hline
\end{tabular}

Column 1 is left-aligned at its natural width, column 3 is right-aligned, and only column 2 is a 5cm p column. The long description wraps at that 5cm, so that cell alone becomes several lines and the row grows taller to fit. Put the same sentence in an l column and it simply stretches sideways without wrapping — the decisive difference p{width} makes. Below the header sits a \hline\hline double rule; single \hline rules cap the top and bottom. The contents of a p column are top-aligned and justified by default, and paragraph indentation \parindent is set to 0 inside it. Wanting the cell centred or bottom-aligned vertically, or set ragged-right instead of justified, takes you into array territory, covered on “Column specifiers in depth”.