LaTeX table generator: tabular code from a grid or spreadsheet
Build a LaTeX table in a spreadsheet-style grid, or paste one from Excel, Google Sheets or a CSV file, and copy clean tabular code with the right packages. Merged cells, booktabs rules, column alignment, captions and full-width tables are all handled. Everything runs in your browser.
On this page
How to use the generator
- Fill the grid. Type into the cells, use Enter to move down (it adds a row at the bottom), or paste a block copied from a spreadsheet into any cell: it spreads across the grid and adds rows and columns as needed. For a whole file, open “Import from a spreadsheet or CSV”.
- Set each column’s alignment with the menu above it: left, centre or right, a wrapping paragraph column of fixed width, a stretching column for full-width tables, or a decimal-aligned number column.
- Merge cells by clicking one cell and Shift-clicking another, then pressing “Merge cells”. A range within one row becomes
\multicolumn; a range spanning rows uses\multirowas well. Click inside a merged cell and press “Split cell” to undo it. - Set the header rows: usually one, or two when a merged heading groups columns underneath it.
- Pick a rule style, caption and label, then copy the code into your document and the
\usepackagelines into the preamble, before\begin{document}.
By default every cell is escaped, so a percentage sign or an underscore in your data cannot break the document. Untick “Escape special characters” when your cells contain LaTeX on purpose, such as $\alpha$ or \textit{n}.
What the example table produces
The grid opens with a small comparison of sorting algorithms. With the default settings the generator writes:
\begin{table}[htbp]
\centering
\caption{Running times of three sorting algorithms.}
\label{tab:sorting}
\begin{tabular}{lccc}
\toprule
\textbf{Algorithm} & \textbf{Best} & \textbf{Worst} & \textbf{Stable} \\ \midrule
Insertion sort & O(n) & O(n\textasciicircum{}2) & Yes \\
Merge sort & O(n log n) & O(n log n) & Yes \\
Quicksort & O(n log n) & O(n\textasciicircum{}2) & No \\
\bottomrule
\end{tabular}
\end{table}and needs only \usepackage{booktabs} in the preamble. Notice that O(n^2) became O(n\textasciicircum{}2): the caret is special in LaTeX. To typeset it as mathematics, untick escaping and write $O(n^2)$ in the cell instead.
LaTeX table basics
A LaTeX table has two layers. The tabular environment draws the grid itself. The table environment around it is a float: a box LaTeX may move to the top or bottom of a page, or to a page of its own, so that it never splits awkwardly. The caption and the label for cross-references belong to the float.
- The column specification, the argument after
\begin{tabular}, has one letter per column:l,corrfor left, centred or right, andp{3cm}for a column of fixed width whose text wraps. A|between letters draws a vertical rule. &separates cells and\\ends a row. Each row must have exactly as many cells as the specification has columns, counting a\multicolumn{n}as n.- Horizontal rules come from
\hline, from\cline{2-3}for a rule under some columns only, or from the booktabs commands below. - Captions go above tables. That is the usual convention for tables (figures put theirs below), and most publisher classes expect it. The
\labelmust come after\caption, or\refwill print the section number instead of the table number.
The float position, such as [htbp], lists the places LaTeX may put the table: here, top, bottom, or a separate float page. Giving it all four is the most reliable choice. A lone [h] is often silently changed to [ht], and if the table does not fit it drifts to the end of the chapter. When a table truly must stay at that point in the text, the float package’s [H] forces it, at the cost of possible gaps at the bottom of the page.
Why booktabs looks better
The booktabs package replaces \hline with three rules of different weights: a heavier \toprule and \bottomrule and a lighter \midrule under the header, with a little extra space around each. Its documentation argues for a short list of habits that make tables easier to read, and they hold up well:
- Never use vertical rules.
- Never use double rules.
- Put units in the column heading, not in every cell.
- Use
\cmidrule(lr){2-3}to group columns under a shared heading, rather than drawing a box around them.
Most journal and conference classes typeset tables in this style, which is why the generator defaults to it. Choose “Full grid” only when a venue or a teacher asks for boxed cells.
Merged cells: multicolumn and multirow
\multicolumn{2}{c}{Accuracy} makes one cell span two columns, with its own alignment. Spanning rows needs the multirow package: \multirow{2}{*}{Method} is written in the top row, and the rows below leave that cell empty. Here is a two-level header from the generator (set “Header rows” to 2), with “Method” and “Time” spanning both header rows:
\begin{table}[htbp]
\centering
\caption{Results with a two-level header.}
\label{tab:results}
\begin{tabular}{lccr}
\toprule
\multirow{2}{*}{\textbf{Method}} & \multicolumn{2}{c}{\textbf{Accuracy}} & \multirow{2}{*}{\textbf{Time (s)}} \\ \cmidrule(lr){2-3}
& \textbf{Train} & \textbf{Test} & \\ \midrule
Baseline & 0.91 & 0.88 & 12 \\
Ours & 0.95 & 0.93 & 15 \\
\bottomrule
\end{tabular}
\end{table}With a two-row header and booktabs, the generator underlines the “Accuracy” group with \cmidrule(lr){2-3}, the booktabs way to show that two columns belong together, and puts \midrule under the second header row. In the full-grid style the generator already writes \cline for rows that a multirow cell continues through, because a full \hline would cut through it.
Tables that are too wide
LaTeX reports an Overfull \hbox warning when a table is wider than the text. You have three good options, all in the generator’s “Width” menu or column menus:
- Let long text wrap. Change the widest text column to
p{4cm}. This is usually the best fix because the font size stays the same. - Use full width with tabularx.
\begin{tabularx}{\linewidth}{X c c}makes the table exactly as wide as the text, and everyXcolumn shares the leftover space and wraps its text. The generator turns the first text column intoXif you have not chosen one. - Scale the whole table with
\resizebox{\linewidth}{!}{…}from graphicx. It is quick, but it shrinks the font too, so use it only for tables slightly too wide. Many venues do not allow scaled-down table text.
For a table that is wider than the page however you set it, rotate it with the sidewaystable environment from the rotating package, or split it into two tables.
Lining up decimal points
Right-aligning numbers only lines up their decimal points when they all have the same number of decimal places. The siunitx package’s S column aligns on the decimal marker whatever the precision. Choose “decimal S” for a column and the generator wraps non-numeric cells, such as the heading, in braces so siunitx does not try to read them as numbers:
\begin{table}[htbp]
\centering
\caption{Decimal points lined up with siunitx.}
\label{tab:mass}
\begin{tabular}{lS}
\toprule
\textbf{Sample} & {\textbf{Mass (g)}} \\ \midrule
A & 1.5 \\
B & 12.25 \\
C & 103.125 \\
\bottomrule
\end{tabular}
\end{table}For finer control, give the column a format, for example S[table-format=3.3] for up to three digits before and three after the point. Add that by hand after copying.
Common errors and how to fix them
| Error message | What it usually means |
|---|---|
Misplaced alignment tab character & | An & appears outside a tabular, usually in text such as “R&D”. Write it as \&; the generator does this when escaping is on. |
Extra alignment tab has been changed to \cr | A row has more cells than the column specification allows. Count the &s, remembering that \multicolumn{n} counts as n columns. |
Missing $ inserted | An unescaped _ or ^ in text. Escape it, or put the expression in $…$. |
Undefined control sequence \toprule | booktabs is not loaded. Copy the preamble lines as well as the table. |
Illegal pream-token | An unknown column letter, such as X outside tabularx or S without siunitx. |
\ref prints the wrong number | \label comes before \caption. Swap them. |
More LaTeX help
For the document around your table, the LaTeX templates guide has a minimal article preamble that already loads booktabs and graphicx, and how to format a CS paper covers figures, tables and captions in the context of a full submission. If your table is a truth table, the truth table generator writes its own LaTeX directly. The booktabs, multirow, tabularx and siunitx manuals on CTAN are the definitive references.