Excel to LaTeX table: export paths and what goes wrong
Excel has no export button that produces a clean LaTeX table. The reliable routes are: paste the cells into a table generator, save as CSV and script the conversion, read the CSV with a LaTeX package, or export the range to PDF and extract the table. Whichever you pick, fix number formats first and expect to escape %, & and _ afterwards.
Convert a table from a PDF or screenshot →By TableToLatex · · Examples tested with pdfLaTeX, TeX Live 2023, pgfplotstable, pandas 3.0
Five ways from Excel to LaTeX
Excel's Save As list has no LaTeX format, so every route goes through something else. You can copy the cells, which puts tab-separated text on the clipboard, and paste them into a table generator. You can use an add-in such as Excel2LaTeX, listed on CTAN, which converts a selected range. You can save a CSV and convert it with a script, or let LaTeX read it directly with pgfplotstable. And if the table exists only as a PDF or picture, you can extract it from that.
The script route is short with pandas. In pandas 3.0.5, to_latex already uses booktabs rules, but it does not escape special characters unless you ask, and it prints floats with six decimals.
import pandas as pd
df = pd.read_csv("results.csv")
print(df.to_latex(index=False, escape=True,
float_format="%.1f", column_format="lrrrl"))\begin{tabular}{lrrrl}
\toprule
Method & Top-1 (\%) & Top-5 (\%) & Params\_M & Note \\
\midrule
Baseline & 71.2 & 90.1 & 25.6 & reproduced \\
Ours & 74.8 & 92.0 & 25.9 & R\&D build \\
\bottomrule
\end{tabular}The pgfplotstable route keeps the data in the CSV and typesets the table when you compile, which suits tables that change often. In a test it worked with plain column names such as Top1. A % in the CSV header line broke it with a "too many columns" error, apparently because the percent sign starts a comment, and a cell containing & gave "Extra alignment tab". Keep the header plain, set the printed names in the styles, and escape the data.
% preamble: \usepackage{booktabs} \usepackage{pgfplotstable}
% \pgfplotsset{compat=1.18}
% results2.csv: Method,Top1,Top5
\pgfplotstabletypeset[
col sep=comma,
string type,
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
columns/Method/.style={column name=Method, column type=l},
columns/Top1/.style={column name={Top-1 (\%)}, column type=r},
columns/Top5/.style={column name={Top-5 (\%)}, column type=r},
]{results2.csv}Escaping is the common problem on every route, and special characters in tables lists each character and its fix. Once the table compiles, decimal alignment with siunitx tidies the numbers, and the proofreading checklist applies when the table came from a picture.
Convert a sheet in seven steps
- 1
Clean the range
Keep one header row and no merged cells or blank spacer rows and columns. Move titles and notes out.
- 2
Set the decimals you will publish
A cell formatted to one decimal may hold more digits. Choose the display format deliberately, because a PDF export shows what the cells display.
- 3
Keep column names plain
Use simple names such as Top1 in the data, and add units and symbols such as (%) in the header text you typeset.
- 4
Export
Copy the range, or save the sheet as CSV UTF-8. For the PDF or screenshot route, capture only the table.
- 5
Convert
Paste into a generator, run the script, or let pgfplotstable read the file, as in the examples above.
- 6
Escape and fix
Make sure %, &, _, # and $ are escaped, whatever tool wrote the table.
- 7
Compile and compare
Check a few values in each row against the spreadsheet, and the number of rows and columns against the range.
The five routes compared
| Route | Good for | Watch out for |
|---|---|---|
| Paste into a table generator | One-off tables | Check that the output is booktabs and that special characters are escaped |
| Excel add-in (Excel2LaTeX on CTAN) | Tables you re-export from Excel | Support depends on your Excel version and operating system |
| CSV and a pandas script | Tables regenerated from data | to_latex does not escape by default; floats print six decimals |
| CSV and pgfplotstable | Tables rebuilt at every compile | A % in the CSV header breaks reading; & in cells needs escaping |
| Export to PDF or screenshot, then extract | Tables with no source data | Proofread digits and decimals afterwards |
What goes wrong
- Unescaped characters. A cell with
&gives "Extra alignment tab has been changed to \cr". A%comments out the rest of its line, including the\\that ends the row, so the errors that follow can look unrelated. - Six decimals. A default pandas export prints 71.200000.
float_formatfixes that, but it applies to every float column. - Merged cells. The merge information is lost on export. Unmerge first and rebuild the header.
- Mangled characters. The classic CSV format can distort non-ASCII characters; use CSV UTF-8.
- Regional separators. Semicolon-delimited files and decimal commas can collapse a table into one column. Open the CSV in a text editor first.
- Symbols in numeric cells. Percent signs, currency symbols and brackets exported with the number need escaping or removing before an S column can read them.
How TableToLatex helps
TableToLatex does not read .xlsx or CSV files. Export the selected range to PDF, or take a screenshot of the cells, and it writes a booktabs tabular with special characters such as %, & and _ escaped. Set the number formats in Excel first, because the PDF shows what the cells display. Start from the LaTeX table generator. The table tool is free and runs in your browser. Paste a tab-separated range from a spreadsheet. See pricing.
Questions about Excel to LaTeX
How do I convert an Excel table to LaTeX?+
There is no LaTeX option in Excel's Save As list. Paste the cells into a table generator, use an add-in, save as CSV and convert it with a script or the pgfplotstable package, or export the range to PDF and extract the table from that.
Which CSV format should I save as?+
Choose CSV UTF-8 if your table contains accents, mu, plus-minus or other non-ASCII characters. One guide to the formats reports that the classic comma-delimited format can distort such characters.
Why does my pandas table not compile?+
In pandas 3.0.5, to_latex writes % & and _ unescaped unless you pass escape=True, so a header such as Top-1 (%) or a cell such as R&D stops LaTeX. Floats are also printed with six decimals unless you give float_format.
How do I handle merged cells in Excel?+
CSV and pasted text have no merge information, so unmerge the cells before exporting and rebuild the header in LaTeX with \multicolumn and \cmidrule. The grouped headers guide shows how.
Can TableToLatex read an .xlsx or CSV file?+
No. Export the selected range to PDF, or take a screenshot of the cells, and upload that. Direct spreadsheet upload is not part of the tool.
Why are my numbers in the wrong format?+
Under some regional settings a CSV may use a semicolon as separator and a decimal comma, so 71.2 arrives as 71,2. Change the separator settings before exporting, or handle it in the script.
How do I put the percent sign in the header only?+
Format the cells as plain numbers, then write the header as Top-1 (\%). Every cell then holds a bare number, which also keeps the column eligible for decimal alignment.
Keep reading
- Special characters
Escaping %, &, _, $, # and friends, inline math, and pasted Unicode errors.
- Decimal alignment
S columns, table-format, signs and ± without misaligned decimals.
- Proofreading OCR tables
A checklist for digits, decimals, minus signs and columns in OCR'd tables.
Have a table in a spreadsheet? Paste it into the table tool, or see all LaTeX table guides.