Using Excel tables in LaTeX

There are many ways to create tables in LaTeX. You can create them by hand or use some program that can save tables in LaTeX format. There are likely converters available for OpenOffice or some of the open source spreadsheet programs. I generally make my LaTeX tables by hand or with Microsoft Excel. On this page I will document methods for converting a table in Excel to a table that can be used in a LaTeX document.

Export a PDF graphic from Excel

One way that I use to get a table from Excel into LaTeX is to export a PDF of the Excel worksheet and then use it as a graphic in LaTeX in place of a tabular environment. You will need to use pdfTeX with the graphicx package to use this method since PDF files need to be included as graphics, although you can always convert a PDF into an EPS file if you wish to use regular LaTeX. This method allows you to create exactly the table you want in Excel and then import it as a graphic in your LaTeX file. I have used it when I just could not figure out how to get a specific look for a table using LaTeX code.

Although this method is simple, you need to install two pieces of software:

PDF Printer Driver: To use this method, you will need to install a printer driver that can print to PDF. I use PDFCreator but you can most likely use Adobe Acrobat Distiller, CutePDF or any other PDF software that prints to a PDF file. Be careful when installing PDFCreator; although it is open source, the installer deceptively installs unwanted browser toolbars. You have to use the custom install options and make sure you deselect all the toolbar options.

PDF crop script: See Autocrop PDF white space.

Export a PDF from Excel

You first create the table exactly as you want it to appear in Excel. Make sure it fits on one page by changing the Page Setup, Font Size and Column / Row Heights / Widths. Then, select the cells corresponding to the table you want and then go to Print. In the print dialog box, select your PDF printer driver (e.g. PDFCreator) and then ask Excel to print only the selected area. Print the table and note where the PDF file is stored. If you open the file, you will see that it was printed on letter sized paper while your table is a bit smaller. If your table is bigger than the page, then you will need to make some adjustments to get it to fit on one page.

Crop white space

If there is unwanted white space around your table, you will need to autocrop the whitespace around the table by running pdfcrop on the file.

When I submitted files to IEEE Transactions on Geoscience and Remote Sensing, I found that removing all the white space sometimes caused the final tables in the proofs to have certain artifacts near the edges. I solved this by making sure that I specified a small margin of 1 bp when I used pdfcrop:

pdfcrop --margins "1" in.pdf cropped.pdf

This will include a small margin of 1 bp (which is something like 1/72 inch) around each side. See [tutorials:publishing:pdf_manipulation_tips#autocrop_pdf_white_space|Autocrop PDF white space]] for instructions on how to use the pdfcrop program.

Embed fonts

I have it written down somewhere in my notes that the cropped.pdf file needs to be post-processed to embed all fonts with the following command:

gswin32c.exe -sDEVICE=pdfwrite -dMaxSubsetPct=100 -dPDFSETTINGS=/prepress -sOutputFile=out.pdf -dNOPAUSE -dBATCH cropped.pdf

The out.pdf file is what you would use. This may be necessary depending on your specific use case for the table. I always perform the above but even I am not too sure if it is necessary. If I have any problems submitting the PDF files for the final submission, I simply take each of my PDF files and use the GIMP to open them and save it as a TIFF file at the right resolution and bit depth (black and white tables are pure black and white, 1-bit per pixel). For IEEE submissions, all tables are apparently rasterized before publication so this has no effect on the final quality.

Include PDF in the LaTeX file

This is fairly easy: whenever you would have had a tabular environment, just replace it with an includegraphics call that includes the PDF of your table.

So this:

\begin{table*}[tbp]
	\caption{Your table caption}
	\label{tab:table1}
	\centering
	\begin{tabular}{|l|l|}
	...
	\end{tabular}
\end{table*}

Becomes this:

\begin{table*}[tbp]
	\caption{Your table caption}
	\label{tab:table1}
	\centering
	\includegraphics[width=5in]{table1.pdf}
\end{table*}

You can scale the table size using the width option of the includegraphics command.

This method of converting from Excel to LaTeX is not without its drawbacks. It is certainly a bit clunky and inelegant and the table needs to be recreated if you modify it. You cannot include citations or indexes inside the table. However, it does allow you to make the table look exactly like your Excel table and is useful when you cannot figure out how to produce a certain table effect in LaTeX.

Export LaTeX code from Excel

A second way to convert from Excel to LaTeX is to use a macro to export LaTeX table code from Excel directly.

I have used xl2latex in the past. I do not know if it works with Excel 2007 and above but it works fine on older versions of Excel. You will have to tweak the code produced by this script to get the table you want but it at least exports all the Excel data for you.

A more updated solution, which I have not tried yet, is an Excel add-in called Excel2LateX. The documentation seems to indicate that it works with Excel 2007 and later.

Export CSV from Excel

You can export an Excel spreadsheet as a CSV file and then use a text processing utility to convert it into a LaTeX table. I have not used this method myself.

Discussion

I would love to hear your feedback. Enter your comment below [ Terms of Use ]:
ZSBIH
 

About Peter Yu I am a research and development professional with expertise in the areas of image processing, remote sensing and computer vision. I received BASc and MASc degrees in Systems Design Engineering at the University of Waterloo. My working experience covers industries ranging from district energy to medical imaging to cinematic visual effects. I like to dabble in 3D artwork, I enjoy cycling recreationally and I am interested in sustainable technology. More about me...

Feel free to contact me with any questions about this site at [user]@[host] where [user]=web and [host]=peteryu.ca

Copyright © 1997 - 2014 Peter Yu