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

  • \begin{tabular}{l c r} … \end{tabular}
    Text mode, no math preview

    Table with a left, a centered and a right-aligned column.

  • a & b & c \\
    Text mode, no math preview

    One row: & between cells, \\ at the end.

  • \begin{tabular}{|l|c|}
    Text mode, no math preview

    | in the column spec draws vertical lines.

  • \hline
    Text mode, no math preview

    Horizontal line across the table.

  • p{4cm}
    Text mode, no math preview

    Column of fixed width whose text wraps.

  • \multicolumn{2}{c}{Text}
    Text mode, no math preview

    Merge cells across two columns.

  • \multirow{2}{*}{Text}
    Text mode, no math preview

    Merge cells down two rows — \usepackage{multirow}.

  • \toprule \midrule \bottomrule
    Text mode, no math preview

    Publication-style rules — \usepackage{booktabs}.

  • \begin{table}[htbp] \centering … \caption{…} \label{tab:x} \end{table}
    Text mode, no math preview

    Floating table with a numbered caption.

  • \begin{array}{|c|c|} \hline a & b \\ \hline \end{array}
    a b

    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.

Templates

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)

    1 2 3 4 5 6
    LaTeX
    \begin{array}{|c|c|c|} \hline 1 & 2 & 3 \\ \hline 4 & 5 & 6 \\ \hline \end{array}
  • Truth table

    p q p ∧ q T T T T F F F T F F F F
    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

    + 0 1 2 0 0 1 2 1 1 2 0 2 2 0 1
    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

    Revenue 1250 Costs − 830 Profit 420
    LaTeX
    \begin{array}{lr} \text{Revenue} & 1250 \\ \text{Costs} & -830 \\ \hline \text{Profit} & 420 \end{array}
  • Value table for a function

    x − 2 − 1 0 1 2 x 2 4 1 0 1 4
    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 result
    NameAgeScore
    Alice2491
    Bob3178
  • 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 result
    ModelAccuracyTime (s)
    A0.9112
    B0.874
  • 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 \multicolumn restores 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 \hline must follow a finished row; without the \\ LaTeX reports "Misplaced \noalign".

    Instead of
    a & b
    \hline
    Write
    a & b \\
    \hline
  • %, &, _, # and $ are special characters in a cell. Escape them or use math mode.

    Instead of
    50% & R&D & x_1
    Write
    50\% & 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, table and \multicolumn are built in. \multirow needs 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 use array with 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 in table with \caption to 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 \hline between 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 of l, c or r; text in that column wraps at the given width. The tabularx package can fill the full line width with X columns.
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 tabular code by hand.

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