Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Manually hacking tables in LaTeX is one of the less funny things when preparing a document. Naturally, there are quite a few tools that promise to simplify this. In fact, I have somewhat lost track of all the tools available, and I'd like to gather your valuable experience into one big post. Some of the tools are mentioned in Tool for manipulating LaTeX tables (HTML to LaTeX), but I feel there's much more around.

I'd suggest that somebody starts an overview with an alphabetic list (so that I can accept this answer and it stays on top), and that everyone replies with a "community wiki" entry, one reply per tool, and inserts the tool into the list.

Personally, I use Excel2LaTeX, but I'm unhappy with having to fire up Windows in order to generate the LaTeX code. I'm thinking of a rewrite as a standalone Python tool using the xlrd library, but I'm not too inclined to reinvent the wheel.

share|improve this question
What, precisely, do you want to achieve with tables? I mean, do you need to format numbers / dates? Do you have repeative tasks in the form of numerical post-processing? Or do you need flexible typesetting (multicolumn/multirow/formatting/typesetting)? What is it that you are missing? auto-alternating colored rows? Or do you need WYSIWYG editing? – Christian Feuersänger Mar 25 '12 at 19:26
1  
Yes to all questions :-) No, honestly. Anything that will take input data and produce \begin{tabular}...\end{tabular} with something sensible inside is welcome here. I'm not asking for how to produce this-and-that output in LaTeX, I guess this has been covered enough on TeX.SX and elsewhere. – krlmlr Mar 25 '12 at 19:37
2  
Not a tool as such, but it may be worthwhile to consider simpler layouts in general -- lots of difficulty arises from trying to reproduce a particular Excel format, when that format would go against many typographical guidelines (e.g., you really don't want that table with the double vertical rules, the borders around each cell, ...) – Mike Renfro Mar 25 '12 at 23:26
@MikeRenfro: I totally agree, in most cases you want what booktabs provides. However, sometimes these tableaux (as the booktabs documentation calls tables with inter-cell rules) are useful. – krlmlr Mar 26 '12 at 0:24
1  
This question has already a very good answer concerning the available table packages: tex.stackexchange.com/questions/12672/…. – Legolas Mar 26 '12 at 6:52
show 1 more comment

17 Answers

Often, I have the use-case that I want to convert a given data table into a "suitable" LaTeX table.

Typically, my data is of numeric type and requires number formatting, perhaps alignment at a decimal point, and in most cases, it requires elementary post-processing (like quotients, differences, gradients).

Since I needed such stuff very often, I wrote some C++ scripts which generated .tex files. It was useful - but I realized very early that it is insufficient; it is just not flexible enough and -as any external tool- produces unwanted complications due to the many tools involved.

My solution is the LaTeX package pgfplotstable. It is a LaTeX table generator, i.e. it converts input data explicitly by a set of configurable rules into something like \begin{tabular}....\end{tabular}.

DISCLAIMER NOTE: I wrote the package.

Among its features are

  • separation of data + format
  • data in form of external data files (CSV with customizable separators) or inline tables (inside of the .tex file)
  • central format definition (for example in the preamble or in form of styles)
  • format numbers with the full power of LaTeX
  • supports simple text columns as well
  • simple support for alternating row colors (colortbl)
  • simple support for standart LaTeX table packages (booktabs, longtable, colortbl, multirow, \multicolumn,...)
  • can produce completely new columns containing postprocessed data, with the powerful pgf math engine
  • can convert single-column output to two-column output
  • is written completely in TeX (no external tools required)
  • highly customizable
  • has a manual with lots of examples.

You may want to inspect the link mentioned above and its examples to see if it fits your needs.

share|improve this answer
Quite some time has passed, and the list grows and grows... Could you please add a CW answer that will contain a list of all tools mentioned plus a direct link to the answer? I will accept this answer so it stays on top. A stub will do, I'll add some more content. Danke schön :-) – krlmlr May 23 '12 at 7:49
Well, someone might change it to a community wikki (I do not know how). But why, precisely do you want to? I mean, there are lots of useful answers and readers of the page get some "community priorization" using the votes. Do you just want to have a "table-of-contents"-answer? IMHO, this is already given by the tex.se answer system here. – Christian Feuersänger May 23 '12 at 17:40
Yes, I would like to have a TOC answer, and I was suggesting that you add a new answer in addition to yours. -- What exactly do you mean by "this is already given by the tex.se answer system here"? Is there a way to display a brief overview of all answers? – krlmlr May 23 '12 at 19:34
Hm, you are right - there is no TOC as you requested. But whenever I try to find something, I am typically happy if I can browse through the answers of users - to see votes of others, comments, potential problems, examples,... a TOC seems somewhat out-of-place on this site (which is a Q&A site, after all). Perhaps you should take the information and write some short article - a survey about available table packages, including a comparison. On tex.se, I would not want to read a TOC answer unless it is automatically generated of the type <pos> <number votes> <title>. – Christian Feuersänger May 25 '12 at 20:21

I was reluctant to publish this humble tool, but here it goes.

excel2datatool

excel2datatool is a Java application I wrote to help me with a personal project. Since it was useful for me and I do believe it's generic enough for other purposes, I decided to make it publicly available. The repository is hosted on GitHub.

The whole idea is to read Microsoft Excel formats and generate .csv + .tex + datatool. Some might argue that this app is basically a CSV converter. Well, it is, but since I had to write a complementary .tex file with \DTLloaddb, I decided to automate steps.

Main screen

The app does not rely on Microsoft Excel. It supports both xls and xlsx out of the box. The usage is quite easy, double-click excel2datatool.jar in Windows and Mac, or run java -jar excel2datatool in Linux. The code is Java 5, 6, 7 and OpenJDK 6 compliant.

Pros

  • There's no need for Microsoft Excel or other office tool.
  • It supports both xls and xlsx formats out of the box.
  • Runs on every major operating system.
  • The LaTeX file generation is optional, so you can use it as a normal CSV converter.

Cons

  • I wrote the app.
  • Since it doesn't rely on external applications, the payload is quite big (9.5Mb).
  • The LaTeX file will contain the most basic datatool usage, with \DTLloaddb. There are no advanced commands.
  • No command line interface.
  • Some people might not like the drag-and-drop style.
  • The application tries its best to parse the Excel file, but there are probably some more complex files which won't be correctly converted.
share|improve this answer
2  
Thumbs up for going open source! – krlmlr Mar 26 '12 at 14:42

Orgmode

Orgmode is a notes/planning mode for Emacs that has a nice table feature.

http://orgmode.org/

Pros

  • Column widths auto-adjust based on contents
  • Behaves as a spreadsheet, including calculations, row/column insert and delete, row/column moves, rectangular selection
  • Import and export of TAB or whitespace separated data
  • Lots of export options (LaTeX, HTML, PDF)

Cons

  • Requires Emacs which has a significant learning curve if you are not already using it
  • Some advanced LaTeX table formatting is still done manually after export
share|improve this answer

R + xtable package

R has the package xtable which generates LaTeX output - useful if you want R results in tabular form. This is an easy way if you're working in the R environment anyway.

Free.

Pros

  • At least the following table types can be converted to a nice table out of the box:

    • One-way and two-way cross tabulations
    • Data frames
    • Model estimation results

    (Anyone more familiar with xtable please append to this list.)

  • Support for booktabs and longtable

  • Optional enclosing in table environment with caption
  • Formatting of numbers and cell contents can be specified
  • Optional filtering ("sanitizing") of TeX special characters
  • More flexibility in conjunction with knitr/Sweave: The definition of the table can be "plain" LaTeX code, and the contents can be generated by an R chunk

Cons

See also the following question for details on using xtable:

How can I use a table generated by R in LaTeX?

The Hmisc package can also generate tabular output from R.

share|improve this answer
2  
I would absolutely recommend this path, but only if you already are in the R environment and if you are creating a more or less "standard" table. Feeding data into R just to produce a (complicated) LaTeX table is possible, but then you might want to consider one of the other options listed here. – krlmlr May 23 '12 at 8:33

Excel2LaTeX

An Excel add-in that converts parts of a spreadsheet into equivalent LaTeX tables.

Free.

http://www.ctan.org/tex-archive/support/excel2latex/

Pros

  • Supports and converts various formatting options:

    • bold/italics
    • alignment
    • cell spanning (horizontal/vertical)
    • struts
    • rotation of cell contents
    • cell border lines
    • booktabs option
  • Configurable: Repeatedly convert the same ranges with one click

Cons

  • Requires Windows or MacOS, and Excel to do the conversion

Disclaimer: I am the current maintainer of this add-in.

share|improve this answer

LaTable

A visual editor for LaTeX tables for Windows and Macintosh. It can be downloaded from CTAN.

The application provides a spreadsheet-like interface with the ability to insert and delete rows and columns, to edit the cells and to set the borders. Tables can be im- and exported as plain text or CSV files or saved in LaTable's own file format .latbl.

A (rather horribly-looking) example:

screenshot of LaTable with an example table

The code generated for this example table:

\begin{tabular}{l|ll|l}
\cline{3-3}
first column & \multicolumn{1}{l|}{second column} & third column & fourth column \\ 
\hline
\multicolumn{1}{c|}{1} & \multicolumn{1}{l|}{2} & 3 & 4 \\ 
\cline{3-3}
5 & 6 & \multicolumn{1}{r}{7} & 8 \\ 
\cline{1-2}\cline{4-4}
9 & \multicolumn{1}{c}{10} & 11 & \multicolumn{1}{l|}{12} \\ 
\cline{4-4}
\end{tabular}

And this is the compiled LaTeX result for comparison:

typeset LaTeX output for the above table

share|improve this answer
1  
The Mac version seems to fail on Snow Leopard. Did anyone tried it with another OS X? – Tobi May 25 '12 at 22:49
Thanks for the app. I will be very more fantastic if it could merge cells on a column too. – PHPst Apr 4 at 17:18
At Mountain Lion, the app doesn't start. Some error message, but crashes before I can read it. – trmdttr May 20 at 12:16

Gnumeric

My prefered solution.

EDIT:

  • You can save the spreadsheet as a full *.tex document (or one which can be "inserted" into an existing one, instructions for this are given as % comments %).
  • Alternatively, (my personal preference) gnumeric allows you to save the spreadsheet as a "table fragment" which will simply give you the plain-vanilla TeX-table :)

See http://projects.gnome.org/gnumeric/doc/file-format-latex.shtml for some further details.

enter image description here

share|improve this answer
2  
Would you be able to provide a little more detail. Perhaps an example of how this you do this? Even though you have low reputation, please upload images as well; remove the preceding !, which will be re-inserted by users with edit privileges. – Werner Apr 18 '12 at 14:03

LyX

LyX has a relatively decent table editor. By selecting View->View Source, one can directly see the resulting LaTeX code and easily copy&paste (and also learn) it from there. Furthermore, it is easy to typeset the result via LaTeX to get an impression on the actual look of the table. Other benefits are built-in support for booktabs and longtable.

enter image description here

The immediate representation of the resulting LaTeX source helped me a lot to actually learn the whistles and bells about LaTeX tabulars. Today I am fluent enough to use LyX only very seldom for this purpose.

share|improve this answer

Calc2LaTeX

For the sake of completeness: You know, there is the spreadsheet programm of the OpenOffice / LibreOffice suite, simply called »calc«. It runs on Linux, Windows and probably on Mac, and it imports Excel spreadsheets quite nicely, if you haven't done more than using tables.

From calc to LaTeX there is an add to calc: calc2Latex

Works nicely, I've been using it for years.

share|improve this answer

csv2latex

For Mac users there is the script csv2latex which allows you to cut and paste spreadsheet cells from Excel, Number or Calc and paste them into your LaTeX source in a variety of popular table formats.

If you use TeXShop as your editor, this functionality is built into the program: there is a Paste Spreadsheet Cells macro in the Macros menu. For other Applescript-aware Mac editors, you can install the script manually.

Disclaimer: I am the author.

share|improve this answer

Emacs align-current and rectangles

OK, this isn't really much of an answer, but if you already have a table in LaTeX and you just want to edit it a bit, it can get a bit messy. If you use emacs then the following tools are super helpful.

First, align-current tries to line up your &s so that your data is more or less in columns. You can then use emacs' C-x r k to cut rectangles out, and C-x r y to paste rectangles back into your table.

Here are some links:

share|improve this answer
Not sure if the links cover this (I am on my phone now) but I had to change my font to be monospaced before The tools you mentioned could actually work for me. – Vivi Dec 20 '12 at 9:20

Numbers2LaTeX

A quick hack from long time ago that converts a table in numbers (for Mac OS X) to a LaTeX table: https://gist.github.com/386384

share|improve this answer

Warning: what's below is more of a tongue-in-cheek answer, but not without a shred of truth in it!

\halign & \valign

Pro

  • It's what you'd eventually get with the other packages (most likely) anyways
  • format agnostic – it's a TeX primitive
  • Once you grok it, you'll be able to produce typographically beautiful tables more easily, and, on the other hand,
  • creating typographically ugly tables is difficult

Contra

  • there's a learning curve
  • creating typographically ugly tables is difficult ;-)

To expand a little, to think about what one is doing when inputting tabular data is that, if, for example, one is working on a spreadsheet program, what you are mentally doing is that every time you want to express that you want to move on to the next horizontal cell you press tab, and every time you want to move to the next row you press enter.

Now, if you just input & instead of tab, and \cr instead of enter, you can skip all the intermediary steps. That is, converting the spreadsheet program generated chunk into tabular (or whatever), and then expanding that out to a \halign.

Similarly, by the time that you've navigated with your mouse through the various menus in the spreadsheet program to express that you want a particular cell to span, say, three columns (this would almost always mean that you are working on a “header” cell), you would have already written \multispan3.

I can already see that I'm writing myself into a corner here, what with the various arguments for cell background colors, cells spanning multiple rows, cells containing vertical mode material, and what have you. So I'm just going to say a sweeping statement about all those things being “bad typography”. ;-).

Hold on, there's a lynch mob knocking on my door…

What I mean is that if you find yourself doing any of the above, more often than not, chances are that you are complicating the information you want to communicate with your table. And that's basically what the word “bad typography” means.

So one strong argument still remains: to visually see the structure of the table, be it in raw text (like in the orgmode answer, vims equivalent, or in the various Markdown extensions), or in graphical programs (like in spreadsheet programs).

This could again be just a s/<colsepchar>/\&/g and s/<rowsepchar>/\\cr/, in whatever chunk you get out from the program of your choice. Like, not a big deal at all. Or alternatively on the TeX side of things, some \catcode madness could take place. Given that the table is simple enough, i.e., not complicating the information you want to communicate with it.

So, given this context and background, I hope my initial joke's not lost on anyone and this answer could happily live in this question! ;-)

share|improve this answer
This does not quite answer the question. Perhaps it would better suit here: tex.stackexchange.com/questions/12672/… – krlmlr Mar 26 '12 at 18:58
All fair. The sed script and the vim mode you mentioned each deserve an own answer. -- You forget that usually you not only want to see the structure of the table, but also to edit it so that it best communicates the information you want to present. Hacking a table is fast, even in LaTeX. Modifying it later is a PITA, and this is the very reason for the question. – krlmlr Mar 27 '12 at 11:48

Kile

http://docs.kde.org/stable/en/extragear-office/kile/wizard_array.html

enter image description here

http://docs.kde.org/stable/en/extragear-office/kile/wizard_array.html

Arrays and tabulars

One of the most boring jobs one can do in LATEX is to write a matrix or a tabular environment. One has to keep track of all the elements, ensure that the environment is well formed, and that all things are where they are supposed to be. Good indentation helps, but there is a simpler way: using Kile's Wizard → Array or Wizard → Tabular menu entries. You will then have a matrix-formed input form that you can easily fill in with your entries. This dialog also offers some options to typeset the tabular material.

share|improve this answer
It seems buggy though; I prefer exporting the raw table via gnumeric! – nutty about natty Apr 13 at 17:36

Direct spreadsheet editing

I've been handling data tables from Excel into LaTeX for lab reports for some while and I have tried several tools. I would like to make the case that unless you consistently require formatting of the same style, then quite often the simplest answer is to direct copy-paste from your spreadsheet into LaTeX with inserted columns including whatever separators you want.

This is particularly useful if you need extra mark-up between columns, such as $ ... $ signs or extra mathematical stuff such as units and the like.

This is arguably best for producing tableaux rather than formal scientific tables, and it does have the disadvantage that it inextricably links up data and formatting. On the other hand, that gives you a lot of freedom for data-dependent formatting. My most recent use of this was the following table, for my dissertation:

enter image description here

I can really not think of other ways of doing this - and particularly of ways that would later on enable me to easily change one of the functions displayed. This is of course not a scientific table, but this tableau is I think the clearest such presentation of these functions. (Spreadsheet and source code available on request.)

share|improve this answer
2  
Sorry, but I just not understand your approach. Maybe you could clarify how exactly you direct copy-paste from your spreadsheet into LaTeX? – Daniel Nov 5 '12 at 8:53
On Excel, simply select all the cells you want and hit ctrl+C, then paste into the LaTeX file. This needs every other column to contain a separator, starting from & or fancier if needed. For the table above an example separator is =CONCATENATE("} & \cellcolor{color",TEXT(L5,"0"),"} \textcolor{text",TEXT(L5,"0"),"}{") – episanty Nov 5 '12 at 14:06
That sounds like a really interesting approach! Maybe you could improve your answer by elaborating on this in more detail and provide a complete MWE? – Daniel Nov 5 '12 at 15:11
An off-topic comment: Those "minus" signs in your headers and first columns are dashes, rather than real minus signs (you probably wrote -xxx instead of $-xxx$)... Remember to use the appropriate one for your reports/papers/etc. ! – YuppieNetworking Feb 19 at 11:32
@YuppieNetworking well caught, you're actually right. I would make the case, on the other hand, that $-xxx$ makes longer dashes in cells where space is at a premium. – episanty Feb 19 at 12:05
show 1 more comment

Did someone miss:

tablas

enter image description here

Some dummy text to fill...

share|improve this answer
LaTable has been mentioned. – krlmlr Nov 5 '12 at 9:10
@user946850: I think I missed!. Removed. – Harish Kumar Nov 5 '12 at 12:16

As you know you can also get a snapshot of your table and add the image file to your file. OK, OK! you are right this is not a good solution for all cases but use it as last resort. In such situation http://getgreenshot.org/ is your assistant.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.