Technology / Software /
28 Jul 2022
Emacs Tables Cheat Sheet
In regular text mode, Emacs can create pretty decent-looking ASCII tables. They look like this:
+-----+--------------+-----------------------+
| ID | Username | Legal Name |
+-----+--------------+-----------------------+
|001 |jdoe |Johnny Doe |
+-----+--------------+-----------------------+
|002 |jfox |Jill Fox |
+-----+--------------+-----------------------+
|003 |pverylon |Paul Verylongname |
+-----+--------------+-----------------------+
|004 |bsimpson |Bart Simpson Jr. |
+-----+--------------+-----------------------+
To insert one, type M-x table-insert
.
There are a bunch of commands for changing the width and height of
rows/columns, inserting more rows or columns, changing the
justification of a row, cell, or column, etc. The easiest way to see
them all is to type M-x table-TAB
(where TAB
means the tab key, so
that it brings up the possible completion options, which are various
table-related commands).
Markdown Mode
Tables work differently when in Markdown mode. If you try to create a regular ASCII table while in Markdown mode, it seems to try and create a table within another table if you press tab. So that’s probably not how you’re intended to do it…
There is actually an entire book dedicated to Markdown mode for Emacs.
To have Emacs assist with table creation, run markdown-insert-table
, which will prompt for the table size/dimensions and let you start filling it in.
Alternately, if you type the header row yourself, then start the divider row by typing a pipe and a hyphen (|-
), Emacs should recognize what you’re doing if you press tab, and fill in the rest of the divider row. Then it will move to the data rows and let you move back and forth through them with tab and shift-tab.
Here’s what a raw table looks like:
Text
| Col One | Col Two | Col Three |
|---------|------------|-----------|
| Data 1 | Data 2 | Data 3 |
| This | is | pretty |
| neat! | Tab | even |
| works | to go | forward |
| Or | backwards! | DONE |
Which should be rendered by Markdown:
Col One | Col Two | Col Three |
---|---|---|
Data 1 | Data 2 | Data 3 |
This | is | pretty |
neat! | Tab | even |
works | to go | forward |
Or | backwards! | DONE |
Markdown Mode Resources
- GitHub for markdown-mode - with good basic documentation in the README
- Guide to Markdown Mode for Emacs - pay-what-you-want ebook (minimum price $7.99 though!)
- Relevant Stack Overflow with some interesting tips, including how to automatically convert from text-mode “grid tables” to Markdown “pipe tables” and vice versa