How to Make a LaTeX Table
A LaTeX table is a tabular environment: \begin{tabular}{l c r} sets three columns (left, center, right), & separates cells and \\ ends a row. Add | in the column spec and \hline for borders, and wrap it in a table environment with \caption to number it.
Table building blocks
- Text mode, no math preview
\begin{tabular}{l c r} … \end{tabular}Table with a left, a centered and a right-aligned column.
- Text mode, no math preview
a & b & c \\One row:
&between cells,\\at the end. - Text mode, no math preview
\begin{tabular}{|l|c|}|in the column spec draws vertical lines. - Text mode, no math preview
\hlineHorizontal line across the table.
- Text mode, no math preview
p{4cm}Column of fixed width whose text wraps.
- Text mode, no math preview
\multicolumn{2}{c}{Text}Merge cells across two columns.
- Text mode, no math preview
\multirow{2}{*}{Text}Merge cells down two rows —
\usepackage{multirow}. - Text mode, no math preview
\toprule \midrule \bottomrulePublication-style rules —
\usepackage{booktabs}. - Text mode, no math preview
\begin{table}[htbp] \centering … \caption{…} \label{tab:x} \end{table}Floating table with a numbered caption.
\begin{array}{|c|c|} \hline a & b \\ \hline \end{array}The math-mode equivalent of tabular; this is what MathJax can draw.
Try it live
Change the formula and the preview redraws as you type. Copy the LaTeX, download a PNG or SVG, copy it for Word, or use Edit here on any example below to load it.
Tables examples
Each result below is drawn from the LaTeX under it. Copy the code, edit it on this page, or open it in the full editor.
Grid with borders (array)
LaTeX\begin{array}{|c|c|c|} \hline 1 & 2 & 3 \\ \hline 4 & 5 & 6 \\ \hline \end{array}Truth table
LaTeX\begin{array}{cc|c} p & q & p \land q \\ \hline T & T & T \\ T & F & F \\ F & T & F \\ F & F & F \end{array}Operation table
LaTeX\begin{array}{c|ccc} + & 0 & 1 & 2 \\ \hline 0 & 0 & 1 & 2 \\ 1 & 1 & 2 & 0 \\ 2 & 2 & 0 & 1 \end{array}Right-aligned numbers
LaTeX\begin{array}{lr} \text{Revenue} & 1250 \\ \text{Costs} & -830 \\ \hline \text{Profit} & 420 \end{array}Value table for a function
LaTeX\begin{array}{c|ccccc} x & -2 & -1 & 0 & 1 & 2 \\ \hline x^2 & 4 & 1 & 0 & 1 & 4 \end{array}
In a LaTeX document
These commands work in the text of a .tex document (Overleaf, TeX Live, MiKTeX), not inside math. The box on the right shows what the compiled PDF looks like.
Basic table with borders
LaTeX\begin{tabular}{|l|c|r|} \hline Name & Age & Score \\ \hline Alice & 24 & 91 \\ Bob & 31 & 78 \\ \hline \end{tabular}Compiled resultName Age Score Alice 24 91 Bob 31 78 Booktabs table with caption
LaTeX\usepackage{booktabs} % preamble \begin{table}[htbp] \centering \caption{Test results} \label{tab:results} \begin{tabular}{lrr} \toprule Model & Accuracy & Time (s) \\ \midrule A & 0.91 & 12 \\ B & 0.87 & 4 \\ \bottomrule \end{tabular} \end{table}Reference it in the text with
Table~\ref{tab:results}.Compiled resultModel Accuracy Time (s) A 0.91 12 B 0.87 4 Merged header cell
LaTeX\begin{tabular}{|l|c|c|} \hline & \multicolumn{2}{c|}{Score} \\ \hline Name & Test 1 & Test 2 \\ \hline Alice & 91 & 88 \\ \hline \end{tabular}"Score" spans the two right-hand columns. The
c|inside\multicolumnrestores the right border that the merged cell would otherwise lose.
How to make a table step by step
Write the column specification first: one letter per column, l, c or r for alignment, or p{width} for a column whose text wraps. Put | between letters where you want vertical lines.
Type each row as cells separated by & and end it with \\. Add \hline before or after a row for horizontal lines. Every row must have as many cells as the specification has columns.
To give the table a number and caption, place the tabular inside \begin{table}[htbp] … \end{table}, add \centering, \caption{…} and \label{tab:name}. LaTeX may move the float to the top of a page; that is normal.
Better-looking tables with booktabs
The booktabs package replaces \hline with \toprule, \midrule and \bottomrule, which have different weights and proper spacing. Its documentation recommends leaving out vertical lines, the style used by most journals.
Build the table visually instead
Typing large tables by hand is slow. The LaTeX table generator on this site lets you fill a grid or paste cells from a spreadsheet, merge cells, choose borders or booktabs, and copy the finished tabular code. If the table is only in a PDF or screenshot, the image converters on the home page can read it.
Common mistakes
More cells than columns gives "Extra alignment tab has been changed to \cr".
Instead of\begin{tabular}{ll} a & b & c \\ \end{tabular}Write\begin{tabular}{lll} a & b & c \\ \end{tabular}A
\hlinemust follow a finished row; without the\\LaTeX reports "Misplaced \noalign".Instead ofa & b \hlineWritea & b \\ \hline%,&,_,#and$are special characters in a cell. Escape them or use math mode.Instead of50% & R&D & x_1Write50\% & R\&D & $x_1$With
[h]alone LaTeX often cannot place the float and moves it anyway. Give it more options, or use[H]from the float package to force the spot.Instead of\begin{table}[h]Write\begin{table}[htbp]
In Overleaf, MathJax and Word
Overleaf and pdfLaTeX
tabular,tableand\multicolumnare built in.\multirowneeds multirow, the rules need booktabs,[H]needs float, and long tables that break across pages need longtable.MathJax and KaTeX
MathJax and KaTeX do not support
tabular. For a table inside math usearraywith the same column letters,|and\hline, as in the examples on this page. In Markdown use a pipe table for plain data.Microsoft Word
Word builds tables with Insert > Table. To move a whole .tex document with its tables into Word, the LaTeX to Word converter handles the file; for a small table, retyping in Word is often quicker.
Tables in LaTeX: questions
- How do I make a table in LaTeX?
- Use
\begin{tabular}{…} … \end{tabular}: one letter per column in the braces,&between cells and\\at the end of each row. Wrap it intablewith\captionto number it. - How do I add borders to a LaTeX table?
- Put
|between the column letters, e.g.{|l|c|r|}, for vertical lines and\hlinebetween rows for horizontal lines. - How do I merge cells in a LaTeX table?
- Across columns:
\multicolumn{2}{c}{text}. Down rows:\multirow{2}{*}{text}with\usepackage{multirow}. - How do I make text wrap inside a table cell?
- Use a
p{4cm}column instead ofl,corr; text in that column wraps at the given width. The tabularx package can fill the full line width withXcolumns. - Can I convert a picture of a table into LaTeX?
- Yes. Upload the screenshot or scan to the image converter on the home page for LaTeX, or open the table generator to build and edit the
tabularcode by hand.
Related LaTeX reference
- Matrix in LaTeXpmatrix, bmatrix, vmatrix and friends: rows with \\, columns with &, plus 2x2, 3x3, augmented and n×n examples.
- Bullet Points in LaTeXitemize for bullet points, enumerate for numbered lists, description for terms, plus nesting, custom bullets and spacing.
- How to Write a Multiline Equation in LaTeXalign and align* for aligned lines, aligned inside $$ … $$, split, gather and multline for long formulas and systems of equations.
- LaTeX table generatorFill a grid or paste from a spreadsheet, merge cells, pick borders, copy the tabular code.
- LaTeX equation editorSymbol panel, live preview, and PNG, SVG, MathML or Word export.
- All LaTeX reference pagesSymbols, math structures and text formatting in one list.
Have the formula as a picture?
Paste a screenshot or photo of the equation and get its LaTeX, ready to copy or open in the editor.
Convert an image to LaTeX