Ads by Google

Friday, July 4, 2008

Quickly Creating LaTeX Tables in Emacs

One of the "that sucks" part of using LaTeX is the part about creating tables. While it is powerful, the idea of all those ampersands, slashes and \hlines makes me go ape. And it takes a couple of edit-compile-view cycles to get into the groove of table writing in LaTeX.

Thankfully Emacs has the table mode as part of the standard distribution. Invoke table-mode as M-x table-insert and create the table. Answer the wizard questions and enter the data for the columns. Once you've written the data into the table, generate the LaTeX table by hitting C-^ and choosing the export format as latex.

Done.

Paste that back into your tex file and add the \usepackage{tabular} or \usepackage{tabularx} to the preamble and compile the file. Adjust the spacing by deleting off unwanted table rows.

This beats the earlier method by a large order in terms of productivity if you can't be bothered to learn LaTeX tables.

And one other tip: Create the emacs table in the tex file and comment it out. If you ever want to make extensive changes to the table, do the following.

  1. Uncomment the emacs table
  2. Move point to the table or highlight the region
  3. M-x table-recognize will make it ready to edited as an emacs table
  4. make the changes and export it again as latex
  5. comment out the emacs table
Keeping the emacs table inline saves some time in creating the table again if you ever need to make changes. Of course, you could edit the LaTeX table code but I don't venture there at unless the changes are cosmetic.