176

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.

6
  • 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? Mar 25, 2012 at 19:26
  • 2
    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, 2012 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, ...) Mar 25, 2012 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, 2012 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, 2012 at 6:52

26 Answers 26

84

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.

4
  • 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, 2012 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. May 23, 2012 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, 2012 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>. May 25, 2012 at 20:21
50

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.
1
  • 10
    Thumbs up for going open source!
    – krlmlr
    Mar 26, 2012 at 14:42
42

Excel2LaTeX

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

Free.

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

Source: https://github.com/krlmlr/Excel2LaTeX

Pros

  • Most Excel formatting is supported.
    • Bold and italic (if applied to the whole cell)
    • Left, right, center, and general alignment (per-cell or per-column)
    • Vertical and horizontal borders (per-cell or per-column, single or double)
    • Font color (using the xcolor package)
    • Fill color (using the colortbl package)
    • Rotation (using the rotating package)
    • Merged cells (using the multirow package, if needed)
    • Can convert \, $, _, ^, %, &, and # to appropriate macros, or leave them in-place
    • Supports booktabs package
    • Uses bigstrut package when booktabs is not available
  • Can surround tabular environment with table environment template
  • Copy output to clipboard or export to a .tex file for inclusion using \include
  • Save table specifications to your Excel worksheet, then export all tables at once
  • Configurable: Repeatedly convert the same ranges with one click

Cons

  • Requires Windows or OS X, and Excel to do the conversion
13
  • The small package "abstract" states that works up to Excel 2010. Do you happen to know if this support is also available for Excel 2013? May 18, 2014 at 23:22
  • 1
    I think it should work in Excel 2013, too. If not, please file a bug.
    – krlmlr
    May 19, 2014 at 12:46
  • 2
    It works perfectly :) May 21, 2014 at 21:02
  • I opened the file, but I don't see an "Add-Ins" tab. Any help?
    – Jeff
    Dec 24, 2014 at 5:46
  • @Jeff: Which Excel version is it?
    – krlmlr
    Dec 24, 2014 at 7:18
38

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
1
  • Great things it can do. How about formating of output? I tried first minor orgtbl-mode and after some troubles all worked ... see details of orgtbl-mode recommended bellow by tex.stackexchange.com/users/9517/t-verron
    – jaromrax
    Jul 24, 2020 at 13:01
24

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.

You can even paste a table copied from e.g. Excel into LyX by following these instructions:

  1. In LyX, insert a table with the same dimensions as the one in the excel.
  2. Place the mouse cursor in the top left cell of the table.
  3. From the menu of LyX, choose Edit → Paste Special → Plain Text, Join Lines.
2
  • Very easy to use. Too bad it doesn't support the combination of multirow and multicolumn. Jul 18, 2018 at 15:30
  • You can paste into a LyX table from e.g. Excel by following the instructions at nd.psychstat.org/blog/copy_tables_from_excel_to_lyx 1. In LyX, insert a table with the same dimensions as the one in the excel. 2. Place the mouse cursor in the top left cell of the table. 3. From the menu of LyX, choose Edit → Paste Special → Plain Text, Join Lines.
    – Gus
    Oct 26, 2021 at 16:50
23

LaTeX Tables Generator

Nice online LaTeX tables generator, supports:

  • multicolumn;
  • multirow;
  • visual editing;
  • custom borders;
  • booktabs styles, coloring and various centering.
5
  • Nice pick! Only thing that is missing is a two-way editing mode.
    – Daniel
    Aug 1, 2014 at 19:59
  • @Daniel You mean paste TeX code and show interactive table? I'm not a creator of this... So can't help. :D
    – m0nhawk
    Aug 1, 2014 at 20:00
  • This looks very nice, but why on earth didn't they open-source the code to allow self-hosting? "Ein Schelm, wer Böses dabei denkt..."
    – krlmlr
    Aug 1, 2014 at 20:38
  • @krlmlr First, why you need self-host it? Second, it's pure Javascript, it is open-source, just without a documentation.
    – m0nhawk
    Aug 1, 2014 at 20:45
  • I use it to answer a question here. It´s a good example of how to use the site. link: tex.stackexchange.com/a/212593/48991
    – Smarzaro
    Nov 18, 2014 at 2:14
22

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.

1
  • 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, 2012 at 8:33
18

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:

1
  • 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, 2012 at 9:20
17

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.

14

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

5
  • 2
    The Mac version seems to fail on Snow Leopard. Did anyone tried it with another OS X?
    – Tobi
    May 25, 2012 at 22:49
  • Thanks for the app. I will be very more fantastic if it could merge cells on a column too. Apr 4, 2013 at 17:18
  • At Mountain Lion, the app doesn't start. Some error message, but crashes before I can read it.
    – trmdttr
    May 20, 2013 at 12:16
  • @trmdttr record your screen with QuickTime and scan through. It might be dependent on Rosetta, which was discontinued with lion. :'( Jun 22, 2013 at 23:00
  • There is no way to merge cells column-wise.
    – PS Nayak
    May 31, 2021 at 4:50
14

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.

2
  • why only for Mac users?
    – Aradnix
    Apr 28, 2017 at 22:17
  • @Aradnix Because at the time I wrote it there was no equivalent of the MacOS pbcopy, pbpaste on other platforms. Whether this has changed, I don't know.
    – Alan Munn
    Apr 28, 2017 at 22:21
13

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.)

9
  • 7
    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, 2012 at 8:53
  • 2
    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"),"}{")
    – E.P.
    Nov 5, 2012 at 14:06
  • 3
    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, 2012 at 15:11
  • 1
    I hadn't thought of using this approach for table generation, but using excel as a line-based string-handling tool is a handy trick (creating batch files to apply complex renaming rules for example)
    – Chris H
    Aug 5, 2013 at 14:57
  • 1
    If anyone is still confused about how to use this, here is a simple example of it in action: tex.stackexchange.com/a/156181
    – thymaro
    Jan 31, 2018 at 7:55
10

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

10

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.

1
  • It seems buggy though; I prefer exporting the raw table via gnumeric! Apr 13, 2013 at 17:36
9

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! ;-)

2
  • This does not quite answer the question. Perhaps it would better suit here: tex.stackexchange.com/questions/12672/…
    – krlmlr
    Mar 26, 2012 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, 2012 at 11:48
8

Orgtbl-minor-mode (for emacs)

This is along the lines of this answer about org-mode. org-mode also provides a minor mode designed specifically to typeset tables with the org syntax, but in a non-org buffer.

Latex is supported out of the box, and there is a tutorial in the org manual.

Pros

  • all those in the answer about org-mode
  • no need to use a separate buffer or mode, all is done in the latex buffer
  • the exporter can be set up on a per-table basis, simply passing parameters to the #+ORGTBL line

Cons

  • the emacs learning curve, mentioned in the answer about org-mode
  • you do not get a full-featured org buffer, which means some keybindings will not be available if they clash with the latex keymap
  • you will also miss on some features of the org swiss-army-knife, for example, the ability to generate the table values from the org buffer, with embedded scripts or code snippets.

For the impatient, though already familiar with org-mode people:

  • turn the minor mode on: M-x orgtbl-mode RET
  • create the template: M-x orgtbl-insert-radio-table RET

enter image description here

  • fill the table

enter image description here

  • export the table: C-c C-c

enter image description here

The two approaches (org and orgtbl) are different in purpose, in my view. org-mode is fine if you don't need to change your data a lot, or if you can afford to do the manual tweaking after every export.

On the other hand, with orgtbl, you can change your table, reexport and recompile in a few keystrokes. It also provides some ways to "automate" the tweaking, but they are still more or less dirty hacks: it goes from overwriting parameters in the export function (which is fine, I guess) to injecting latex code in the cells (for example additional line space can be added in the first cell of the next line).

1
7

Inlage

Insert → Insert Table (Ctrl + Shift + T ) will open the following window (where I have filled some data):

enter image description here

Upon pressing insert, the code is inserted in the editor where the cursor is:

enter image description here


Importing from Excel

Let us say we have an excel table with formulae:

enter image description here

Select the values and copy:

enter image description here

Now paste in the inlage editor (directly). The Insert Table window will appear as shown below:

enter image description here

Press the Insert button after editing if any. Values will be converted in to LaTeX code as shown below:

enter image description here

5

Cals

The CALS table model is the historic precursor of the HTML table model. It is easier in use and offers more capabilities than tabularx.

By employing the cals package, tables in LaTeX can be directly defined in CALS syntax.

Here is the documentation:

and an example:

\documentclass{article}

%text symbols
\usepackage{textcomp}

%table
\usepackage{cals}

\begin{document}
\makeatletter
\begin{calstable}
\colwidths{{12mm}{18mm}{18mm}{12mm}{15mm}}
\def\cals@cs@width{0pt} %no vertical lines
\setlength{\cals@paddingT}{3pt}
\setlength{\cals@paddingB}{2pt}
\alignC
\thead{\brow \cell{sectie} \cell{$D_{out}$\,(m)} \cell{$D_{in}$\,(m)} \cell{$\ell$\,(m)} \cell{$A$\,(m\texttwosuperior)} \erow}
\brow \cell{1} \cell{0,060} \cell{0,056} \cell{1,80} \cell{0,66} \erow
\brow \cell{2} \cell{0,055} \cell{0,051} \cell{1,80} \cell{0,60} \erow
\brow \cell{3} \cell{0,050} \cell{0,046} \cell{1,80} \cell{0,54} \erow
\brow \cell{4} \cell{0,045} \cell{0,041} \cell{1,80} \cell{0,49} \erow
\brow \cell{5} \cell{0,040} \cell{0,036} \cell{1,80} \cell{0,43} \erow
\brow \cell{6} \cell{0,035} \cell{0,031} \cell{1,80} \cell{0,37} \erow
\tfoot{\brow \alignR \nullcell{ltb} \nullcell{tb} \nullcell{tb} \nullcell{tbr} \spancontent{Totaal:} \alignC \cell{3,09} \erow}
\end{calstable}
\makeatother
De totale oppervlakte bedraagt 3,09\,m\texttwosuperior.
\end{document}

enter image description here

5
  • From the manual of the cals package: "The TeX code for tables is supposed to be generated automatically." Which tools generate TeX code in this particular syntax?
    – krlmlr
    Jun 21, 2013 at 9:00
  • erm... isn't this about XML-style CALS?
    – krlmlr
    Jun 21, 2013 at 10:00
  • @krlmlr The so far only tool which generates TeX in this syntax by interpreting XML CALS tables is unfortunately not released to public. Perfectionism is sometimes bad.
    – olpa
    Jun 21, 2013 at 13:40
  • @olpa: Thanks for the cals package, it looks like a sweet option. Why don't you also push your tool to GitHub, in whatever state it is? Then we'd only have to find a way to convert spreadsheet or R tables to XML CALS...
    – krlmlr
    Jun 21, 2013 at 13:49
  • @krlmlr A part of the tool is here. cals.py splits multirow and multicolumn cells to simple cells with annotations, which make xslt code very easy. I'll try to commit the xslt part in a few days.
    – olpa
    Jun 22, 2013 at 20:48
5

LaTeX-tables

With this new interface it is possible to create quickly a table: there are many options as from this image:

enter image description here

It is very easy and there are the options: Import from LaTeX and Load from Excel.

4

AppleScript Excel2Latex

I wrote this AppleScript to help me convert my selection in Microsoft Excel 2011 Mac to LateX code. I have it configured to export into a longtabutable, but it can easily be configured to accommodate other needs.

Limitations: Script ignores bold or italicized words

(*
Must have \usepackage{longtable} and \usepackage{tabu} in preamble.
Export is saved to Desktop as "Excel Table Export.tex"
written in 2013 by Jonathan Komar
*)

set target_file to (((path to desktop folder) as text) & "Excel Table Export.tex")
my write_to_file("", target_file, false)

tell application "Microsoft Excel"
    set mySel to selection
    tell selection to set {rowCount, columnCount} to {count rows, count columns}

    set columnsList to {}
    repeat columnCount times
        set end of columnsList to "X[m] "
    end repeat

    set myList to {}

    set writeThis to "\\begin{longtabu}{ " & (columnsList as string) & "}\n\\tabucline[.4mm,black]1\n"
    my write_to_file(writeThis, target_file, true)
    repeat with rowStep from 1 to (rowCount)
        repeat with columnStep from 1 to (columnCount)
            set currentValue to value of cell columnStep of row rowStep of mySel
            if columnStep is equal to columnCount and rowStep is 1 then
                set writeThis to currentValue & "\\\\\n\\tabucline[.05mm,black]1\n"
                my write_to_file(writeThis, target_file, true)
            else
                if columnStep is not equal to columnCount then
                    set writeThis to currentValue & " & "
                    my write_to_file(writeThis, target_file, true)
                else
                    set writeThis to currentValue & "\\\\\n"
                    my write_to_file(writeThis, target_file, true)
                end if
            end if
            if rowStep is equal to rowCount and columnStep is columnCount then
                set writeThis to "\\tabucline[.4mm,black]1\n\\end{longtabu}"
                my write_to_file(writeThis, target_file, true)
            end if
        end repeat
    end repeat
end tell

return myList as string



on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean)
    try
        set the target_file to the target_file as text
        set the open_target_file to ¬
            open for access file target_file with write permission
        if append_data is false then ¬
            set eof of the open_target_file to 0
        write this_data to the open_target_file starting at eof as «class utf8»
        close access the open_target_file
        return true
    on error
        try
            close access file target_file
        end try
        return false
    end try
end write_to_file

AppleScript Numbers2LateX

This is a template script for iWork Numbers. It has issues: You need to set the rows and columns in the script manually or by adjusting the table to fit your content. I am not sure how to get a row and column count of a selection in Numbers. Warning: This script does not seem to work as well as the excel script. It must be improved!

(*
Must have \usepackage{longtable} in preamble.
Export is saved to Desktop as "Numbers Table Export.tex"
written in 2013 by Jonathan Komar
*)

set target_file to (((path to desktop folder) as text) & "Numbers Table Export.tex")
my write_to_file("", target_file, false)

tell application "Numbers"
    set rowCount to (get row count of table 1 of sheet 1 of document 1)
    set columnCount to (get row count of table 1 of sheet 1 of document 1)

    tell front document
        tell table 1 of sheet 1
            set columnsList to {}
            repeat columnCount times
                set end of columnsList to "X[m] "
            end repeat

            set myList to {}
            set writeThis to "\\begin{longtabu}{ " & (columnsList as string) & "}\n\\tabucline[.4mm,black]1\n"
            my write_to_file(writeThis, target_file, true)
            repeat with rowStep from 1 to rowCount
                repeat with columnStep from 1 to (columnCount - 1)
                    set currentValue to value of cell rowStep of column columnStep
                    if columnStep is equal to columnCount and rowStep is 1 then
                        set writeThis to currentValue & "\\\\\n\\tabucline[.05mm,black]1\n"
                        my write_to_file(writeThis, target_file, true)
                    else
                        if columnStep is not equal to columnCount then
                            set writeThis to currentValue & " & "
                            my write_to_file(writeThis, target_file, true)
                        else
                            set writeThis to currentValue & "\\\\\n"
                            my write_to_file(writeThis, target_file, true)
                        end if
                    end if
                    if rowStep is equal to rowCount and columnStep is columnCount then
                        set writeThis to "\\tabucline[.4mm,black]1\n\\end{longtabu}"
                        my write_to_file(writeThis, target_file, true)
                    end if
                end repeat
            end repeat
            get value of cell 1 of column 2

        end tell
    end tell
end tell



on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean)
    try
        set the target_file to the target_file as text
        set the open_target_file to ¬
            open for access file target_file with write permission
        if append_data is false then ¬
            set eof of the open_target_file to 0
        write this_data to the open_target_file starting at eof as «class utf8»
        close access the open_target_file
        return true
    on error
        try
            close access file target_file
        end try
        return false
    end try
end write_to_file
4

Creating LaTeX Table from Excel Worksheet

Save the contents of the excel sheet as csv file and use it in the LaTeX code. Here is an example:

enter image description here
The above is an excel sheet. Saving it in csv format as contents.csv.

natural,two,three
1,2,3
2,4,6
3,6,9
4,8,12
5,10,15
6,12,18
7,14,21
8,16,24
9,18,27
10,20,30

Now, the following code illustrates an example:

\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstabletypeset[
    col sep=comma,
    string type,
    columns/natural/.style={column name=natural, column type={|l}},
    columns/two/.style={column name=two, column type={|l}},
    columns/three/.style={column name=three, column type={|c|}},
    every head row/.style={before row=\hline,after row=\hline},
    every last row/.style={after row=\hline},
    ]{contents.csv}
\end{document} 

enter image description here

2
  • 1
    The top answer covers pgfplotstable quite good, i think?
    – Johannes_B
    Aug 2, 2014 at 11:58
  • @Johannes_B can you be a bit more clear? Aug 2, 2014 at 12:03
3

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.

2
  • If screenshots are your thing (which they shouldn't be, ew ;)) the default snipping tool in windows is easier to use. (At the time of writing, the linked seems to be a windows-only tool.) Aug 1, 2013 at 0:12
  • You'd have to be desperate. If you have a vector image file (pdf) there are better ways than that, it's really only suitable when you only have an image of the table, then I would say retype it.
    – Chris H
    Aug 5, 2013 at 15:01
3

excel2latex.js

An online tool that converts .xlsx files (but no .xls files) to LaTeX tables. JavaScript based. The code is on GitHub. Haven't tested it yet, just found this answer.

3

CSV + R editor (RStudio or TexStudio) + sweave + knitr

Even better if you write your Latex document directly as a Rnw document and sweave it with TexStudio or RStudio.

The steps would be :

  1. Create CSV containing data
  2. Import the csv as a data frame in an R chunck
  3. Create table with kable or xtable (highly customizable)
  4. Knit the Rnw document with the option to keep the tex file (so you can eventually fine tune the result)
  5. Enjoy a dynamic document with the power of Latex and R
2

I use a simple VBA for Excel function called ConcateMe to generate the rows of a table in a text cell in your excel file.

You will have to set up the main environment of the table yourself, but the script below is very handy in that it creates the table rows in a cell.

Use the function for each table row separately. Then copy the contents of the cell and paste into LaTex. Presto.

Nothing fancy, but very fast, and because it is a function, it is always up to date.

Function ConcatMe(Rng As Range) As String
Dim cl As Range
   ConcatMe = ""
   countr = 0
   For Each cl In Rng
   countr = countr + 1
      pasty = cl.Text
      If pasty = vbNullString Then pasty = " "
      If countr = 1 Then ConcatMe = ConcatMe & pasty Else ConcatMe = ConcatMe & " & " & Trim(pasty)
   Next cl
   ConcatMe = ConcatMe & " \\"
End Function
2
  • So if the range spans multiple lines, how do you manage that? Can you show a screenshot of your use-case?
    – Werner
    Jul 28, 2016 at 17:57
  • See for example, this link (db.tt/TqD89ylF) Aug 1, 2016 at 14:16
1

Python Macro LibreCalc2Latex

I've found this macro calc2booktab and tested it on LibreCalc 6.3. It works really nice. It has a couple of options. So far I've tried it out also on Overleaf and it also works as intendend.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .