LaTeX Tables: How to Make a Table in LaTeX and Overleaf

A table in LaTeX is a tabular environment: you declare the columns, separate cells with & and end rows with \\. Wrapping it in a table float adds a caption and a number you can reference. From there, packages handle everything else: booktabs for clean rules, multirow and \multicolumn for merged cells, tabularx for fixed widths, longtable for tables that run over several pages, xcolor for shaded rows and siunitx for decimal-aligned numbers. This guide starts with a complete table you can paste into any document and then covers each of those techniques, the float placement rules, landscape tables, footnotes inside tables, and the errors a tabular can throw. Every example is standard LaTeX, so it works unchanged in Overleaf, Octree or a local TeX installation; the Tables in Overleaf section covers the Overleaf-specific details.

Quick Start: A Complete Table

Most tables in papers and theses look like this one: a table float holding a caption, a label and a booktabs-ruled tabular. Copy it, change the column specifier and the rows, and you are done.

\documentclass{article}
\usepackage{booktabs}
\begin{document}

\begin{table}[htbp]
  \centering
  \caption{Accuracy of three models on the test set.}
  \label{tab:accuracy}
  \begin{tabular}{lcc}
    \toprule
    Model    & Accuracy (\%) & Parameters (M) \\
    \midrule
    Baseline & 91.2          & 12            \\
    Large    & 94.7          & 48            \\
    Ours     & 95.3          & 15            \\
    \bottomrule
  \end{tabular}
\end{table}

Table~\ref{tab:accuracy} summarises the results.

\end{document}

The pieces, from the outside in: table is the float that gets a number and can move to a good position on the page; [htbp] lists the positions you allow; \centering centres the content; \caption gives the caption (above the table, by convention) and steps the table counter; \label stores that number for \ref; and \begin{tabular}{lcc} declares three columns: left-aligned, centred, centred. Everything below walks through these parts in detail.

tabular in LaTeX: Column Specs, Lines and Alignment

The foundation of every LaTeX table is the tabular environment. It takes a column specification that defines how many columns the table has and how each column is aligned. Cells in the same row are separated by &, and rows are terminated by \\. Horizontal lines are drawn with \hline.

\documentclass{article}
\begin{document}

\begin{tabular}{l c r}
  \hline
  Left & Centre & Right \\
  \hline
  A1   & B1     & C1    \\
  A2   & B2     & C2    \\
  A3   & B3     & C3    \\
  \hline
\end{tabular}

\end{document}

The column specifier {l c r} defines three columns: left-aligned, centred, and right-aligned respectively. Each & advances to the next column, and each \\\\ ends the current row.

Everything about a tabular is decided by that column specification. One letter per column sets its alignment, | between letters draws a vertical line, and a width turns a column into a wrapping paragraph. Inside the table, \hline draws a full rule, \multicolumn merges cells across columns and \multirow merges them down rows:

\documentclass{article}
\usepackage{multirow}
\begin{document}

\begin{tabular}{|l|c|r|p{3cm}|}
  \hline
  \multicolumn{3}{|c|}{\textbf{Merged header over three columns}} & Notes \\
  \hline
  Left & Centre & Right & A paragraph column wraps long text inside 3cm. \\
  \hline
  \multirow{2}{*}{Two rows} & a & 1 & \\
                            & b & 2 & \\
  \hline
\end{tabular}

\end{document}
In the spec or tableMeaning
l, c, rLeft, centred, right-aligned column, as wide as its widest cell
p{3cm}Paragraph column 3 cm wide; text wraps and is top-aligned (m and b with the array package)
|Vertical line between columns; || for a double line
@{}Removes the padding at that edge, e.g. @{}lr@{}
*{4}{c}Repeats a column type: four centred columns
& and \\Next cell; end of row
\hline, \cline{2-3}Full horizontal line; line under columns 2 to 3 only
\multicolumn{3}{|c|}{...}One cell spanning 3 columns, with its own alignment and lines
\multirow{2}{*}{...}One cell spanning 2 rows (multirow package); leave the cells below it empty

\hline with vertical lines is the classic grid look. For papers, the booktabs rules (\toprule, \midrule, \bottomrule) and no vertical lines read better; both styles are compared in Professional Tables with booktabs below, and each part of the specification is covered in detail in the next sections.

The table Environment

The tabular environment creates the table content itself, but it does not make the table "float" or give it a caption. To add those features, wrap the tabular inside a table environment. The table environment is a floating container that LaTeX can position automatically for optimal page layout.

\begin{table}[htbp]
  \centering
  \caption{Experimental results for three samples.}
  \label{tab:results}
  \begin{tabular}{l c c}
    \hline
    Sample & Temperature (\textdegree C) & Yield (\%) \\
    \hline
    A      & 100                          & 85         \\
    B      & 150                          & 92         \\
    C      & 200                          & 78         \\
    \hline
  \end{tabular}
\end{table}

Key elements of the table environment:

  • \centering – Centres the table horizontally on the page.
  • \caption{...} – Adds a numbered caption. Place it above or below the tabular.
  • \label{tab:results} – Creates a reference label so you can use \ref{tab:results} elsewhere.
  • [htbp] – Placement specifiers: here,top, bottom, page of floats. LaTeX tries each in order.

\centering vs. the center environment

Inside a float, use the \centering declaration, not \begin{center} ... \end{center}. Both centre the table, but the center environment is a list internally and adds vertical space above and below, which produces an uneven gap between the caption and the table. The center environment is the right choice only for a tabular placed directly in the text, outside any float, where that extra space is wanted.

Float placement: [htbp], [H] and \FloatBarrier

A table is a float: LaTeX puts it where the page layout works best, which is not always where you wrote it. The placement argument lists the positions you accept. [htbp] allows all four and is the usual choice; [t] forces the top of a page; [!htb] relaxes LaTeX's internal limits on how much of a page a float may take. If a table must appear exactly where it is written, the float package provides [H]:

\usepackage{float}

\begin{table}[H]   % exactly here, no floating
  ...
\end{table}

[H] can leave large blank areas at page bottoms, so a gentler tool is often better: \FloatBarrier from the placeins package stops floats from drifting past a given point, typically the end of a section:

\usepackage[section]{placeins}   % barrier at every \section
% or, manually, wherever needed:
\FloatBarrier

If many tables pile up at the end of a chapter, \clearpage flushes them all onto a new page. The warning Too many unprocessed floats means more than eighteen floats are waiting; a \clearpage or \FloatBarrier fixes it.

Column Alignment

The column specifier string controls alignment and structure. LaTeX provides several column types out of the box:

SpecifierAlignmentDescription
lLeftLeft-aligned column, natural width
cCentreCentre-aligned column, natural width
rRightRight-aligned column, natural width
p{width}TopParagraph column with specified width, top-aligned
m{width}MiddleParagraph column, vertically centred (requires array package)
b{width}BottomParagraph column, bottom-aligned (requires array package)
% Paragraph columns are useful for wrapping long text
\begin{tabular}{l p{5cm} r}
  \hline
  Name  & Description                              & Score \\
  \hline
  Alpha & A long description that wraps within the
          specified 5cm column width.               & 95    \\
  Beta  & Another description, also wrapped.        & 88    \\
  \hline
\end{tabular}

Column widths with p, m and b

The l, c and r columns are as wide as their widest cell and never wrap. For text that should wrap, give the column a width. p{width} is built in and aligns cell contents to the top of the row; m{width} (middle) and b{width} (bottom) come from the array package. Width can be absolute (3cm) or relative to the text width (0.4\textwidth):

\usepackage{array}
\usepackage{booktabs}

\begin{tabular}{l m{4cm} b{3cm}}
  \toprule
  Top-aligned (l) & Middle-aligned (m) & Bottom-aligned (b) \\
  \midrule
  Short & This cell contains enough text to wrap onto a second and
          third line, and the other cells align to its middle. & Last line \\
  \bottomrule
\end{tabular}

Text in a paragraph column is justified by default, which can look ragged in a narrow cell. The array package's >{...} prefix runs a command at the start of every cell in that column, so >{\raggedright\arraybackslash}p{4cm} gives left-aligned, unjustified text. The \arraybackslash restores \\ as the row terminator, which \raggedright otherwise redefines. The same prefix sets fonts for a whole column: >{\bfseries}l for a bold first column, or >{\small}c for a smaller one.

You can also add vertical lines between columns by placing | in the column specifier, although modern typographic practice discourages heavy use of vertical rules:

% Vertical lines (old style — prefer booktabs instead)
\begin{tabular}{|l|c|r|}
  \hline
  Left & Centre & Right \\
  \hline
  A    & B      & C     \\
  \hline
\end{tabular}

Adding Lines and Rules

LaTeX provides several ways to add horizontal and partial lines to tables. The built-in commands work but produce results that are typographically inferior to thebooktabs package.

Basic Lines

% \hline draws a full-width horizontal line
\begin{tabular}{l c r}
  \hline
  Header 1 & Header 2 & Header 3 \\
  \hline
  A        & B        & C        \\
  D        & E        & F        \\
  \hline
\end{tabular}

% \cline{i-j} draws a partial line from column i to column j
\begin{tabular}{l c r}
  \hline
  Header 1 & Header 2 & Header 3 \\
  \cline{1-2}
  A        & B        & C        \\
  \cline{2-3}
  D        & E        & F        \\
  \hline
\end{tabular}

The booktabs Package

The booktabs package provides three commands that produce cleaner, more professional rules with proper spacing:

  • \toprule – A thick line at the top of the table
  • \midrule – A thinner line separating the header from the body
  • \bottomrule – A thick line at the bottom of the table
\usepackage{booktabs}

\begin{tabular}{l c r}
  \toprule
  Header 1 & Header 2 & Header 3 \\
  \midrule
  A        & B        & C        \\
  D        & E        & F        \\
  G        & H        & I        \\
  \bottomrule
\end{tabular}

Professional Tables with booktabs

The booktabs package is the gold standard for typesetting tables in LaTeX. It follows a key principle: never use vertical rules andnever use double rules. Compare the two approaches:

Before: Traditional Style

% Old-fashioned table with vertical and double lines
\begin{tabular}{|l|c|r|}
  \hline\hline
  Name  & Grade & Score \\
  \hline\hline
  Alice & A     & 95    \\
  \hline
  Bob   & B+    & 88    \\
  \hline
  Carol & A-    & 91    \\
  \hline\hline
\end{tabular}

After: booktabs Style

% Clean, professional table with booktabs
\usepackage{booktabs}

\begin{tabular}{lcr}
  \toprule
  Name  & Grade & Score \\
  \midrule
  Alice & A     & 95    \\
  Bob   & B+    & 88    \\
  Carol & A-    & 91    \\
  \bottomrule
\end{tabular}

The booktabs version is cleaner, more readable, and matches the style used in most published journals. The booktabs package also provides\cmidrule{i-j} for partial horizontal rules with proper trimming:

\begin{tabular}{lcc}
  \toprule
              & \multicolumn{2}{c}{Scores} \\
  \cmidrule(lr){2-3}
  Student     & Midterm & Final \\
  \midrule
  Alice       & 92      & 95   \\
  Bob         & 85      & 88   \\
  Carol       & 90      & 91   \\
  \bottomrule
\end{tabular}

The (lr) after \cmidrule trims the rule slightly on the left and right, creating visual separation between column groups. You can use(l), (r), or (lr) as needed.

Row and Column Spacing

Default tabular spacing is tight: rows sit at the normal line height and each column gets 6pt of padding on either side. Four settings control it. \arraystretch scales every row height, \\[6pt] adds space after one row, \tabcolsep sets the padding on each side of every column, and @{} in the column specifier replaces that padding for one gap.

Row height: \arraystretch and \\[6pt]

\arraystretch is a multiplier, so 1.5 makes every row half again as tall. Set it with \renewcommand (it is a macro, not a length) and keep the change inside the table environment or a group so it does not leak into the rest of the document. For extra space after a single row, add an optional length to its \\:

% Taller rows for the whole table
\begin{table}[htbp]
  \centering
  \renewcommand{\arraystretch}{1.5}
  \begin{tabular}{|c|c|}
    \hline
    Cell 1 & Cell 2 \\
    \hline
    Cell 3 & Cell 4 \\
    \hline
  \end{tabular}
\end{table}
% The table environment ends the group, so \arraystretch is back to 1.0 here

% Extra space after one row
\begin{tabular}{lr}
  \toprule
  Item & Price \\[6pt]
  \midrule
  Widget & 5.00 \\
  Gadget & 3.50 \\[1ex]
  Total & 8.50 \\
  \bottomrule
\end{tabular}

\\[6pt] adds space below the row; it cannot add space above. For headroom above a row, or to pad cells symmetrically, use the methods under cell padding below.

\addlinespace with booktabs

In a booktabs table, \addlinespace inserts a small vertical gap (0.5em by default) between rows, a cleaner way to group rows than \midrule or an empty row. It takes an optional length:

\usepackage{booktabs}

\begin{tabular}{lcc}
  \toprule
  Item & Qty & Price \\
  \midrule
  Widget A & 10 & 5.00 \\
  Widget B & 25 & 3.50 \\
  \addlinespace
  Gadget C & 4 & 12.00 \\
  \addlinespace[1em]
  \textbf{Total} & 39 & 185.50 \\
  \bottomrule
\end{tabular}

Column separation: \tabcolsep, @{} and \hspace

\tabcolsep is the padding on each side of a column, so the gap between two columns is twice its value (12pt by default). It is a length, so change it with \setlength. The @{...} specifier replaces the padding at one position with whatever you put inside the braces: empty braces remove it, which is how a table is made flush with the text margin, and \hspace widens one particular gap without touching the others.

% Wider gaps between all columns (default is 6pt)
\setlength{\tabcolsep}{10pt}

% Remove the padding at the left and right edges
\begin{tabular}{@{}lcc@{}}
  \toprule
  Name & Value & Unit \\
  \midrule
  Speed & 100 & km/h \\
  Time & 2.5 & h \\
  \bottomrule
\end{tabular}

% A 1cm gap between the first two columns only
\begin{tabular}{c@{\hspace{1cm}}cc}
  a & b & c \\
  d & e & f
\end{tabular}

% Put separator text in the gap: a colon between label and value
\begin{tabular}{r@{ : }l}
  width & 10cm \\
  height & 5cm
\end{tabular}

The @{} trick matters most in a tabularx or in a table that should be exactly \textwidth: without it the rules of a booktabs table overhang the text block by \tabcolsep on each side.

Cell padding: struts, cellspace and array

To add space above or below the content of a single cell, insert an invisible rule (a “strut”): \rule{0pt}{3ex} adds height above the baseline, \rule[-1ex]{0pt}{0pt} adds depth below it. The cellspace package automates this for whole columns, and the array package's >{...} and <{...} hooks insert code before and after every cell in a column, which also works for horizontal padding:

% Struts in individual cells
\begin{tabular}{|c|c|}
  \hline
  \rule{0pt}{3ex}Tall header & Second header \rule[-1.5ex]{0pt}{0pt} \\
  \hline
  a & b \\
  \hline
\end{tabular}

% cellspace: minimum vertical padding for every cell in an S-prefixed column
\usepackage{cellspace}
\setlength{\cellspacetoplimit}{4pt}
\setlength{\cellspacebottomlimit}{4pt}
\begin{tabular}{|Sc|Sc|}
  \hline
  $\frac{a}{b}$ & $\frac{c}{d}$ \\   % fractions no longer touch the lines
  \hline
\end{tabular}

% array: extra horizontal padding before and after a column's content
\usepackage{array}
\begin{tabular}{>{\hspace{1em}}c<{\hspace{1em}} l}
  padded & plain
\end{tabular}

A fully spaced table

\usepackage{booktabs}

\begin{table}[htbp]
  \centering
  \renewcommand{\arraystretch}{1.3}
  \setlength{\tabcolsep}{12pt}
  \begin{tabular}{@{}lcc@{}}
    \toprule
    \textbf{Item} & \textbf{Qty} & \textbf{Price} \\
    \midrule
    Widget A & 10 & \$5.00 \\
    Widget B & 25 & \$3.50 \\
    \addlinespace
    \textbf{Total} & 35 & \$137.50 \\
    \bottomrule
  \end{tabular}
  \caption{Row and column spacing applied together}
\end{table}
ProblemFix
Table looks cramped\renewcommand{\arraystretch}{1.3} and a larger \tabcolsep
Header touches the rule below it\\[0.5ex] after the header row, or \addlinespace with booktabs
Fractions or tall symbols touch \hlineA strut \rule{0pt}{3ex}, or the cellspace package
Rules stick out past the text margin@{} at both ends of the column specifier
Spacing changes leak into later tablesSet \arraystretch and \tabcolsep inside the table environment or a {...} group
Inconsistent gaps between rowsUse booktabs rules and \addlinespace instead of empty rows

Multi-Column Cells

The \multicolumn command allows a single cell to span multiple columns. This is commonly used for group headers or merged cells:

\multicolumn{number_of_columns}{alignment}{text}
\usepackage{booktabs}

\begin{tabular}{lccc}
  \toprule
  \multicolumn{1}{l}{Name} & \multicolumn{3}{c}{Scores} \\
  \cmidrule(lr){2-4}
                            & Math & Science & English \\
  \midrule
  Alice                     & 95   & 92      & 88     \\
  Bob                       & 82   & 90      & 95     \\
  Carol                     & 91   & 88      & 84     \\
  \bottomrule
\end{tabular}

The first argument is the number of columns to span, the second is the alignment specifier for the merged cell (e.g., c, l, r), and the third is the cell content. You can also use \multicolumn{1}to override the alignment of a single cell.

Multi-Row Cells

The multirow package provides the \multirow command for cells that span multiple rows:

\multirow{number_of_rows}{width}{text}
\usepackage{booktabs}
\usepackage{multirow}

\begin{tabular}{llc}
  \toprule
  Category     & Item     & Price \\
  \midrule
  \multirow{2}{*}{Fruit}
               & Apple    & \$1.20 \\
               & Banana   & \$0.80 \\
  \midrule
  \multirow{3}{*}{Vegetable}
               & Carrot   & \$0.90 \\
               & Potato   & \$1.10 \\
               & Onion    & \$0.70 \\
  \bottomrule
\end{tabular}

The * for the width argument tells LaTeX to use the natural width of the text. You can also specify an explicit width like 2cm if needed.

Table Width Control

By default, LaTeX tables are only as wide as their content requires. To make a table span the full text width (or any specific width), use the tabularx package.

Using tabularx

\usepackage{tabularx}

% Syntax: \begin{tabularx}{width}{column spec}
% The X column type stretches to fill available space

\begin{tabularx}{\textwidth}{l X r}
  \toprule
  Name  & Description                                & Score \\
  \midrule
  Alpha & This column stretches to fill the remaining
          width of the table.                         & 95   \\
  Beta  & The X column type distributes space evenly. & 88   \\
  \bottomrule
\end{tabularx}

You can use multiple X columns, and the available space is divided equally among them:

\begin{tabularx}{\textwidth}{l X X}
  \toprule
  ID & Title          & Description       \\
  \midrule
  1  & First item     & Detailed info     \\
  2  & Second item    & More details here \\
  \bottomrule
\end{tabularx}

Full-Width Tables in Two-Column Documents

If your document uses a two-column layout, use the table* environment to create a table that spans both columns:

\documentclass[twocolumn]{article}
\usepackage{booktabs}

\begin{document}

% This table spans both columns
\begin{table*}[t]
  \centering
  \caption{Results across all experiments.}
  \begin{tabular}{lcccccc}
    \toprule
    Method & Exp 1 & Exp 2 & Exp 3 & Exp 4 & Exp 5 & Average \\
    \midrule
    Ours   & 95.2  & 93.1  & 94.8  & 96.0  & 92.7  & 94.4   \\
    Base   & 90.1  & 88.5  & 89.3  & 91.2  & 87.6  & 89.3   \\
    \bottomrule
  \end{tabular}
\end{table*}

\end{document}

Long Tables

Standard LaTeX tables cannot break across pages. If your table is longer than a single page, use the longtable package. It automatically breaks the table across pages and can repeat headers and footers on each page.

\usepackage{longtable}
\usepackage{booktabs}

\begin{longtable}{lcc}
  % First header (appears on the first page)
  \caption{Complete list of experimental results.}
  \label{tab:longresults} \\
  \toprule
  Experiment & Temperature (\textdegree C) & Yield (\%) \\
  \midrule
  \endfirsthead

  % Continuation header (appears on subsequent pages)
  \multicolumn{3}{c}{\textit{Continued from previous page}} \\
  \toprule
  Experiment & Temperature (\textdegree C) & Yield (\%) \\
  \midrule
  \endhead

  % Footer on every page except the last
  \midrule
  \multicolumn{3}{r}{\textit{Continued on next page}} \\
  \endfoot

  % Footer on the last page
  \bottomrule
  \endlastfoot

  % Table body
  Trial 1  & 100 & 85 \\
  Trial 2  & 110 & 87 \\
  Trial 3  & 120 & 90 \\
  Trial 4  & 130 & 88 \\
  Trial 5  & 140 & 91 \\
  Trial 6  & 150 & 93 \\
  Trial 7  & 160 & 89 \\
  Trial 8  & 170 & 86 \\
  Trial 9  & 180 & 82 \\
  Trial 10 & 190 & 79 \\
  % ... more rows as needed
\end{longtable}

The four sectioning commands control what appears where:

  • \endfirsthead – Marks the end of the header for the first page
  • \endhead – Marks the end of the header for continuation pages
  • \endfoot – Marks the end of the footer for all pages except the last
  • \endlastfoot – Marks the end of the footer for the final page

A longtable is not a float, so it takes no [htbp] argument and no surrounding table environment; the caption goes inside, as shown, and counts as a normal table in the list of tables. Because the column widths are computed across all pages, LaTeX needs two or three compilation runs before the columns stop shifting. A table that is only slightly too tall for one page can often be rescued with \small or \footnotesize before the tabular; anything longer belongs in a longtable.

Landscape Tables

A table with many columns may fit only when rotated. There are two approaches, and they differ in whether the page or just the table rotates.

The pdflscape package rotates whole pages: everything inside the landscape environment, including headers, footers and page numbers, is typeset in landscape, and in a PDF viewer the page itself is displayed rotated. Floats inside the environment stay on those pages:

\usepackage{pdflscape}
\usepackage{booktabs}

\begin{landscape}
  \begin{table}
    \centering
    \caption{A wide table on a landscape page.}
    \begin{tabular}{lcccccccc}
      \toprule
      Run & Jan & Feb & Mar & Apr & May & Jun & Jul & Aug \\
      \midrule
      A   & 1   & 2   & 3   & 4   & 5   & 6   & 7   & 8   \\
      B   & 2   & 3   & 4   & 5   & 6   & 7   & 8   & 9   \\
      \bottomrule
    \end{tabular}
  \end{table}
\end{landscape}

The rotating package instead rotates only the float. Its sidewaystable environment is a drop-in replacement for table that turns the table and its caption by 90 degrees, always on a page of its own, while the page number and running headers stay upright. This is what most journals and theses expect for printed output:

\usepackage{rotating}

\begin{sidewaystable}
  \centering
  \caption{The same table, rotated as a float.}
  \begin{tabular}{lcccccccc}
    ...
  \end{tabular}
\end{sidewaystable}

Use pdflscape for documents read on screen, where a rotated page is convenient, and sidewaystable for print. Do not combine the two for the same table.

Colored Tables

The xcolor package (with the table option) and thecolortbl package let you add background colours to rows, columns, and individual cells.

\usepackage[table]{xcolor}
% or: \usepackage{colortbl}

% Define custom colours
\definecolor{headerblue}{RGB}{0, 102, 204}
\definecolor{lightgray}{gray}{0.9}
\definecolor{lightblue}{RGB}{220, 235, 255}

Row Colours

\usepackage[table]{xcolor}
\usepackage{booktabs}

\begin{tabular}{lcc}
  \toprule
  \rowcolor{headerblue}
  \textcolor{white}{Name} &
  \textcolor{white}{Grade} &
  \textcolor{white}{Score} \\
  \midrule
  \rowcolor{lightgray}
  Alice & A  & 95 \\
  Bob   & B+ & 88 \\
  \rowcolor{lightgray}
  Carol & A- & 91 \\
  Dave  & B  & 84 \\
  \bottomrule
\end{tabular}

Alternating Row Colours

\usepackage[table]{xcolor}

% Automatically alternate row colours
\rowcolors{2}{lightgray}{white}

\begin{tabular}{lcc}
  \toprule
  Name  & Grade & Score \\
  \midrule
  Alice & A     & 95    \\
  Bob   & B+    & 88    \\
  Carol & A-    & 91    \\
  Dave  & B     & 84    \\
  Eve   & A+    & 98    \\
  \bottomrule
\end{tabular}

Cell Colours

\usepackage[table]{xcolor}

\begin{tabular}{lcc}
  \toprule
  Name  & Status                          & Score \\
  \midrule
  Alice & \cellcolor{green!25}Pass        & 95    \\
  Bob   & \cellcolor{red!25}Fail          & 42    \\
  Carol & \cellcolor{green!25}Pass        & 91    \\
  Dave  & \cellcolor{yellow!25}Borderline & 60    \\
  \bottomrule
\end{tabular}

Column Colours

\usepackage[table]{xcolor}
\usepackage{array}

% Apply colour to an entire column using the > directive
\begin{tabular}{l >{\columncolor{lightblue}}c c}
  \toprule
  Name  & Highlighted & Normal \\
  \midrule
  Alice & 95          & A      \\
  Bob   & 88          & B+     \\
  Carol & 91          & A-     \\
  \bottomrule
\end{tabular}

Merging Rows and Columns Together

For complex table layouts, you can combine \multicolumn and\multirow in the same table. This is common in academic papers where you need hierarchical headers or grouped data.

\usepackage{booktabs}
\usepackage{multirow}

\begin{tabular}{llccc}
  \toprule
  \multirow{2}{*}{Department} &
  \multirow{2}{*}{Employee} &
  \multicolumn{3}{c}{Quarterly Sales (\$k)} \\
  \cmidrule(lr){3-5}
  & & Q1 & Q2 & Q3 \\
  \midrule
  \multirow{3}{*}{Engineering}
    & Alice   & 120 & 135 & 142 \\
    & Bob     & 98  & 110 & 105 \\
    & Carol   & 115 & 128 & 138 \\
  \midrule
  \multirow{2}{*}{Marketing}
    & Dave    & 200 & 220 & 245 \\
    & Eve     & 180 & 195 & 210 \\
  \bottomrule
\end{tabular}

When combining these commands, remember that:

  • \multicolumn takes effect on a single row and merges cells horizontally.
  • \multirow takes effect starting from the current row and merges cells vertically.
  • In the rows spanned by \multirow, leave the corresponding cell empty (just use & to skip it).

Decimal Alignment with siunitx

Numbers in a column should line up on the decimal point, not on their left or right edge, so that 3.5 and 12.25 can be compared at a glance. The siunitx package provides the S column type for exactly this. Each cell is parsed as a number, aligned on the decimal marker, and the header is centred over the column when wrapped in braces:

\usepackage{siunitx}
\usepackage{booktabs}

\begin{tabular}{l S[table-format=2.2] S[table-format=1.3]}
  \toprule
  Sample & {Mass (g)} & {Error} \\
  \midrule
  A      & 3.5        & 0.012   \\
  B      & 12.25      & 0.1     \\
  C      & 7          & 0.005   \\
  \bottomrule
\end{tabular}

table-format=2.2 reserves space for two digits before the decimal point and two after; it sets the column width so all entries align. Any cell that is not a number, such as the header or a dash, must be wrapped in {...}, otherwise siunitx tries to parse it and reports Invalid numerical input. S columns also handle units and uncertainties: 3.5(2) prints as 3.5(2), and \qty{3.5}{\gram} in a normal column prints a number with its unit and correct spacing.

Footnotes in Tables

\footnote inside a tabular produces the mark but loses the text, because a tabular is typeset as a box. The usual fix is the threeparttable package, which puts notes directly under the table:

\usepackage{booktabs, threeparttable}

\begin{table}[htbp]
  \centering
  \begin{threeparttable}
    \caption{Results with table notes.}
    \begin{tabular}{lr}
      \toprule
      Method & Score \\
      \midrule
      Ours\tnote{a} & 94.7 \\
      Baseline     & 91.2 \\
      \bottomrule
    \end{tabular}
    \begin{tablenotes}
      \footnotesize
      \item[a] Averaged over five runs.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

Alternatives, including \footnotemark with \footnotetext after the float and the minipage trick, are covered in LaTeX Footnotes.

Table Captions and Labels

Captions and labels are essential for numbered tables and cross-references. The\caption command generates a numbered caption (e.g., "Table 1: ..."), and \label creates a reference anchor.

Caption Placement

In most style guides, the caption for a table goes above the table (unlike figures, where captions typically go below). This is because readers scan a caption before reading the table data:

\begin{table}[htbp]
  \centering
  \caption{Summary of experimental results.}
  \label{tab:summary}
  \begin{tabular}{lcc}
    \toprule
    Method & Accuracy & F1 Score \\
    \midrule
    Ours   & 94.5     & 93.2     \\
    Base   & 89.1     & 87.8     \\
    \bottomrule
  \end{tabular}
\end{table}

Cross-Referencing Tables

Once you have labelled a table, you can refer to it anywhere in the document:

As shown in Table~\ref{tab:summary}, our method
outperforms the baseline by 5.4 percentage points.

% Use \pageref for the page number
The full results are in Table~\ref{tab:summary}
on page~\pageref{tab:summary}.

Always place \label after \caption, not before. If you place it before the caption, the reference number may be incorrect.

Caption for a tabular outside a float

\caption only works inside a float such as table; on a bare tabular it stops with \caption outside float. When a table must not float (inside a minipage, a multi-column layout or a box), use \captionof from the caption package, which numbers it as a table all the same:

\documentclass{article}
\usepackage{caption}
\begin{document}

\begin{center}
  \captionof{table}{A caption on a non-floating tabular.}
  \label{tab:inline}
  \begin{tabular}{lr}
    \hline
    Item & Value \\
    \hline
    A    & 1     \\
    \hline
  \end{tabular}
\end{center}

Table~\ref{tab:inline} stays exactly where it is written.

\end{document}

For the caption below the table instead of above, simply move \caption after \end{tabular}; with the caption package, add \captionsetup[table]{skip=6pt} if the gap between caption and table looks wrong in that position.

Numbering style and cleveref

Tables are numbered 1, 2, 3 in article and per chapter (2.1, 2.2) in book and report. To number per section in an article, or to change the format, adjust the counter in the preamble; and with cleveref, \cref writes the word “Table” for you:

\counterwithin{table}{section}            % Table 1.1, 1.2, 2.1, ...
\renewcommand{\thetable}{\Roman{table}}   % Table I, II, III

\usepackage{cleveref}                      % after hyperref, if used
As shown in \cref{tab:summary} ...         % table 1
\Cref{tab:summary} shows ...               % Table 1

The caption text itself is styled with the caption package: \usepackage[font=small, labelfont=bf]{caption} gives a small caption with a bold “Table 1:” label, which is what many journals ask for.

Useful Packages for Tables

Here is a summary of the most important packages for LaTeX tables and what each one provides:

PackagePurposeKey Commands
booktabsProfessional horizontal rules\toprule, \midrule, \bottomrule, \cmidrule
multirowCells spanning multiple rows\multirow{rows}{width}{text}
tabularxTables with automatic-width columnsX column type, \begin{tabularx}{width}
longtableTables spanning multiple pages\endfirsthead, \endhead, \endfoot, \endlastfoot
colortblColoured rows, columns, and cells\rowcolor, \cellcolor, \columncolor
siunitxAlign numbers by decimal pointS column type
arrayExtended column specifiersm{}, b{}, >{}, <{} directives

A typical preamble for a document with professional tables looks like this:

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage[table]{xcolor}
\usepackage{siunitx}
\usepackage{array}

Using a LaTeX table generator: Excel and CSV to tabular

Most of the work in a LaTeX table is mechanical: one & per column, one \\ per row, and a column specifier that matches. A LaTeX table generator does that part for you, which removes the most common source of Extra alignment tab and Misplaced \noalign errors. With the free Octree Table to LaTeX converter (linked below) it takes three steps:

  1. Export your data as CSV. In Excel use File → Save As → CSV, in Google Sheets File → Download → Comma-separated values; include the header row.
  2. Upload the CSV file to the converter and check the rendered preview next to the generated tabular code.
  3. Copy the code into your document, inside a table float if it needs a caption and label, then finish by hand: the spacing commands above, siunitx for numeric columns and \multicolumn for merged cells.

Hand-write the tabular instead when the table is small (a few rows you would type faster than export), when its structure matters more than its data (merged cells with \multirow, nested headers, a longtable across pages), or when a script regenerates the numbers on every run, in which case let the script write the .tex file and \input it as shown in the Overleaf section.

Generate tables automatically

Typing & and \\ by hand is where most table errors come from. Upload a CSV exported from Excel or Google Sheets to the free Table to LaTeX converter and get a booktabs table with the right column specifier, ready to drop into a table float.

Open the Table to LaTeX converter →

Tables in Overleaf

A table in Overleaf is the same tabular code as everywhere else, and every example on this page compiles there as-is. Overleaf builds projects with TeX Live, which already contains booktabs, multirow, tabularx, longtable, xcolor and siunitx, so there is nothing to install: add the \usepackage lines to the preamble of main.tex and use the commands.

Inserting a table

In Overleaf's Visual Editor, the toolbar has a table button: pick the number of rows and columns from a grid and an empty table is inserted at the cursor. In Code Editor you type or paste the tabular yourself. The toolbar is quickest for a small table you fill in by hand; for data that already lives in a spreadsheet, the table generator in the previous section is faster. Either way, the booktabs rules shown above usually look cleaner than \hline and vertical lines.

Keeping tables in separate files

Large projects are easier to manage with each table in its own file. In Overleaf, create a tables folder, add results.tex to it, and pull it into the float with \input. Paths are relative to the project root, and the .tex extension can be left out:

% main.tex
\documentclass{article}
\usepackage{booktabs}
\begin{document}

Table~\ref{tab:results} lists the results.

\begin{table}[htbp]
  \centering
  \caption{Results on the test set.}
  \label{tab:results}
  \input{tables/results}
\end{table}

\end{document}
% tables/results.tex
\begin{tabular}{lcc}
  \toprule
  Model    & Accuracy (\%) & F1   \\
  \midrule
  Baseline & 91.2          & 0.89 \\
  Ours     & 95.3          & 0.94 \\
  \bottomrule
\end{tabular}

Keep \caption and \label in main.tex as shown, so the table file holds only data and can be regenerated from a script or the table generator without touching the surrounding text.

Common Overleaf table problems

  • Undefined control sequence on \toprule or \multirow. The package is not loaded. Add \usepackage{booktabs} or \usepackage{multirow} to the preamble, before \begin{document}.
  • A PDF appears but the table looks wrong. Overleaf can still produce a PDF after an error, so a half-rendered table often hides one. Open the logs, fix the first error listed, and recompile; later errors are frequently knock-on effects of the first.
  • The table runs into the margin. Use tabularx or p-columns as described in Table Width Control, or scale the whole table with \resizebox{\linewidth}{!}{...} from graphicx as a last resort, since it also scales the font.

Frequently Asked Questions

How do I make a table in Overleaf?

Write a tabular environment inside a table float in main.tex, exactly as in any LaTeX document: declare the columns, separate cells with & and end rows with \\. Add \usepackage{booktabs} to the preamble for \toprule, \midrule and \bottomrule. Overleaf compiles with TeX Live, so booktabs, multirow, tabularx, longtable, xcolor and siunitx are already installed; you only load them. In Visual Editor, the toolbar also has a table button that inserts an empty table of the size you pick from a grid.

Why does \toprule give "Undefined control sequence" in Overleaf?

\toprule, \midrule and \bottomrule come from the booktabs package, and \multirow from the multirow package. The error means the package is not loaded: add \usepackage{booktabs} (or \usepackage{multirow}) to the preamble of main.tex, before \begin{document}, and recompile.

How do I add a caption to a table in LaTeX?

Put the tabular inside a table environment and add \caption{...} above it, then \label{tab:name} right after the caption: \begin{table} \centering \caption{Results} \label{tab:results} \begin{tabular}{lc} ... \end{tabular} \end{table}. Refer to it with Table~\ref{tab:results}. For a tabular that is not in a float, load the caption package and use \captionof{table}{...}.

What does \begin{tabular}{|l|c|r|} mean?

It starts a table with three columns: l is left-aligned, c centred and r right-aligned, and each | draws a vertical line, so there are lines at both edges and between every column. Cells are separated with & and rows end with \\. Use p{3cm} instead of a letter for a column of fixed width whose text wraps.

Is there a free LaTeX table generator?

Yes. The Octree Table to LaTeX converter at tools.useoctree.com is free and needs no account: export your spreadsheet from Excel or Google Sheets as CSV, upload it, and copy the generated tabular code into your document. Add the caption, label and any merged cells by hand.

Common Errors

Tables produce some of LaTeX's least helpful messages. These are the ones that come up most, with what they actually mean:

Message or symptomCauseFix
Misplaced \noalign\hline, \midrule or \cline not at the start of a row, usually because the previous row is missing its \\Add \\ to the end of the previous row
Extra alignment tab has been changed to \crA row has more & than the column specifier allowsCount the columns; check for a missing \\ that merged two rows, or an unescaped & in text (write \&)
Illegal character in array argSomething in the column specifier is not a known column type: X without tabularx, S without siunitx, m without array, or a typoLoad the package that defines the column type, and check for typos in the specifier
Overfull \hbox and the table runs into the marginThe natural width of the columns exceeds the text widthUse p{} or tabularx to wrap text, a smaller font (\small before the tabular), a landscape page, or as a last resort \resizebox{\textwidth}{!}{...} from graphicx
Missing \endgroup inserted or Missing } inserted at \end{tabular}Unbalanced braces in a cell, often from a \multicolumn or \multirow with the wrong number of argumentsCheck that every \multicolumn has three arguments and every \multirow has three
Footnote number appears, footnote text does not\footnote inside tabularthreeparttable, or \footnotemark + \footnotetext (see above)
Table appears pages away from its textFloat placement[htbp] or [!htb]; \FloatBarrier from placeins; [H] from float
Invalid numerical input in an S columnText in a siunitx number columnWrap non-numeric cells in braces: {Header}
Wrong table number from \ref\label placed before \captionMove \label after \caption, then compile twice
Package xcolor Error: Undefined color or \rowcolor undefinedxcolor loaded without the table option, or a color name not defined\usepackage[table]{xcolor}; define custom colors with \definecolor

Quick Reference

A handy reference table for column types and common commands:

Column TypeAlignmentPackageDescription
lLeftBuilt-inLeft-aligned, natural width
cCentreBuilt-inCentre-aligned, natural width
rRightBuilt-inRight-aligned, natural width
p{width}TopBuilt-inParagraph column, top-aligned
m{width}MiddlearrayParagraph column, vertically centred
b{width}BottomarrayParagraph column, bottom-aligned
XJustifiedtabularxStretches to fill available width
SDecimalsiunitxAligns numbers by decimal point

Common table commands at a glance:

CommandPackageDescription
\hlineBuilt-inFull-width horizontal line
\cline{i-j}Built-inPartial horizontal line from column i to j
\toprulebooktabsThick top rule
\midrulebooktabsThin middle rule
\bottomrulebooktabsThick bottom rule
\cmidrule{i-j}booktabsPartial rule with optional trimming
\multicolumn{n}{align}{text}Built-inMerge n columns into one cell
\multirow{n}{width}{text}multirowMerge n rows into one cell
\rowcolor{color}colortbl / xcolorSet background colour for a row
\cellcolor{color}colortbl / xcolorSet background colour for a cell
\columncolor{color}colortbl / xcolorSet background colour for a column

Next Steps

Now that you can create professional tables in LaTeX, explore more topics:

Free LaTeX Tools

Building tables by hand can be tedious. Use our free tools to speed up your workflow:

Ready to start writing?

Try Octree – the AI-powered LaTeX editor that makes writing faster and easier.

Try Octree Free →