Tables in LaTeX

Have you ever created any tables in LaTeX? In my opinion tables are definitely one (the only one) of the weak points of this wonderful typesetting system. With LaTeX most common tasks (write a „normal“ report, standard formatting etc) are extremely easy, but creating tables with seems to be an occasion to tear one’s hair. Really? No!
Edit table in OOo-CalcIndeed there is a wonderful trick (thanks to Jutta for this hint) to easily add wonderful tables to your document: simply create it as a spreadsheet in the spreadsheet program of your favourite office suite (I recommend OpenOffice). Do not format the table, this is pure waste of time as all formatting will be lost later.
After you are done, save the table as Text CSV (.csv). Instead of saving the file with the standard CSV options, modify these options as follows: set the field delimiter to & and remove the text delimiter. This creates a .csv-file, in our example it is
replacement of dishes&300$&14$
fines for speeding&3500$&0$
fines for dodging paying the fare in trains&0$&600$
bail to be released after drug tracking&400$&1400$

Open this .csv-file in a text editor and copy its content to your favourite LaTeX editor (e.g. Kile). Now you simply have to modify this code to change it into a correct LaTeX table: add \\ at the end of each line of the table, add a \hline where you want a horizontal line, escape special characters (e.g. in our example the $ sign) with a backslash \ and add (i.e. copy it from another document) the surrounding code like \begin{tabular}:
replacement of dishes&300\$&14\$ \\
fines for speeding&3500\$&0\$ \\
fines for dodging paying the fare in trains&0\$&600\$ \\
bail to be released after drug tracking&400\$&1400\$ \\
\caption{Personal Expenses in 2006 and 2007.}

Table Created with LaTeXEven though the above code still seems to be complicated (it isn’t as you will realise when taking a closer look at it), this trick really simplifies the task of creating a table in LaTeX. When using it, the creation of tables in LaTeX does not become the easiest part of LaTeX but it is no more tedious and the countless advantages of LaTeX over Word make editing a report fare more efficient with LaTeX despite the rather cumbersome creation of tables.

I will talk about the advantages of LaTeX in a later post, so just look back later (or better: subscribe to my RSS-Feed).

4 thoughts on “Tables in LaTeX

  1. Thank you. I am leery of using something that can’t be done in a cli, however, to get something like tables within tables is rather tricky and completely unintuitve. This idea at least makes me think that I should be using awk or perl to create my tables and then turning them into latex tables.


  2. Could you please let me know when you find a better (= i.e. command line, without this GUI stuff…) solution? Creating these LaTeX-tables is really tedious, and it’s the only tedious thing in LaTeX 😉

  3. Erwin

    Gnumeric, Kspread and I think also OpenOffice Calc have all Tex Export (or Save As) capabilities. Also some formatting will be saved.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.