Org-mode basics II: use simple tables in your notes

In the first post of this series we looked at using org-mode to structure your notes. Today we’ll look at adding simple tables to your notes. Later we’ll see how these tables can be used for advanced features like spreadsheet style calculations, or using them as the input and/or output of code, and also how they export nicely in html or pdf documents. For now we’ll just use them as simple static tables in our notes.

I suggest adding the text below to the org file from last time to build an org-mode notebook on how to keep org-mode notebooks!

* Tables
Hopefully you can see straight away that the simple structure provided
by org-mode gives a nice way to keep an electronic note book.

Often it is nice to include tables in our notes. Org handles this by
using | to separate columns, and a line of --- (inserted with C-c -)
to add horizontal lines.

Exercise: start typing in this table below; type the first line in
verbatim
 1) when you get to the "s" of comments, press TAB to go to the next
    line
 2) go up to the previous line and use C-c - to add the row of dashes
 3) next enter a few lines of data, using TAB to go through the
    cells - you should notice the columns changing width as needed

| ID | x |  y | comments       |
|----+---+----+----------------|
| A  | 2 |  4 | blah           |
| B  | 3 |  9 | blah           |
| C  | 4 | 16 | blah blah blah |
| D  | 5 | 25 | blah           |

Now, you can move rows and columns around using M-arrow and insert or
delete rows and columns using M-S-arrow. Try this out now.

** Creating and exporting tables
You can create an empty table using C-c | to run the command
org-table-create-or-convert-from-region, which will prompt for table
dimensions if no region is selected.

The same command can easily convert some text to a table; select the
following text and use C-c | to run the command
org-table-create-or-convert-from-region again to convert the text to a
table

 ID  x   y
 A   2   4
 B   3   9
 C   4  16
 D   5  25

You can also save tables to their own files by putting the cursor in
the table and using M-x org-table-export. You'll be asked for a
file name and a format. For the format, type orgtbl-to and press TAB
to see the available options (e.g. orgtbl-to-csv will convert to csv
in the output file).

** Formulae
You can use formulae to do arithmetic on tables, and use them like a
spreadsheet. This is something I keep meaning to use more often, but
don't generally find I need it. One useful command is C-c + which runs
org-table-sum to sum the numbers in the current column.

For more on this, see e.g. this introduction. Notice that we just
added a link in our org-mode file - this is a teaser for what we will
cover next!