Emacs: Edit Tables
This page shows you how to use emacs's “table” feature. This feature will let you format tabular data by ASCII drawing. Then you can interactively create and edit tables with emacs commands to insert/delete column/row. You can also convert it to HTML or LaTeX formats.
Creating a Table
Creating a New Empty Table
To create a table, Alt+x table-insert
.
It'll ask you these questions: {Number of columns, Number of rows, Cell width, Cell height}. You can just press Enter key to accept the default. You can change the values for each later. The result will look like this:
+-----+-----+-----+ | | | | +-----+-----+-----+ | | | | +-----+-----+-----+ | | | | +-----+-----+-----+
Press Tab or Shift+Tab to go to neighbor cells.
Creating a Table from Comma Separated Values
If you already have a table data, such as Comma Separated Values (CSV) from spreadsheets, or even from a existing HTML table, you can create a table from that.
Let's say you have this comma separated values:
,A,B,C 1,1a,1b,1c 2,2a,2b,2c 3,3a,3b,3c
Select the whole text, then Alt+x table-capture
. It'll ask you these questions:
- Column delimiter regexp. Answer: ,.
- Row delimiter regexp. Answer newline, by typing Ctrl+q Ctrl+j.
- Justify. Type one of {left,center,right}.
- Minimum cell width. This is the number of chars per cell. Type 5 for example.
Emacs will then change it to this:
+-----+-----+-----+-----+ | |A |B |C | +-----+-----+-----+-----+ |1 |1a |1b |1c | +-----+-----+-----+-----+ |2 |2a |2b |2c | +-----+-----+-----+-----+ |3 |3a |3b |3c | +-----+-----+-----+-----+
In the minibuffer prompt, to enter a tab character (ASCII 9), type Ctrl+q Tab. To enter a newline character, type Ctrl+q Ctrl+j.
Note: In a emacs buffer, newlines are always represented by the Line Feed char (“\n”, LF; ASCII 10). You don't have to worry about what OS you are using. [see Emacs: Newline Representations ^M ^J ^L]
Using Table Menu

Once you have created a table, you can use the menu to do things. The menu [Table] will appear when your cursor is on a table cell.
If you prefer using commands, you can type Alt+x table- then press Tab to see a list of all commands.
Some of the most useful are:
table-insert-row
table-insert-column
table-delete-row
table-delete-column
table-generate-source
output to HTML, LaTeX, CALStable-release
output to space separated values
Generating Output
To generate output for your table, pull the menu [Table ▸ table-generate-source] or Alt+x table-generate-source
. Then, you can choose one of HTML, LaTeX, or cals (a XML based one).
To output to space delimited values, Alt+x table-release
.
Note: emacs's table feature is not very robust. If you work with importing/exporting actual spread sheets or address books, with hundreds of rows or columns, emacs table feature does not handle it well.