Tables in Org-mode

Here’s another nice thing about blogging in org-mode: easy tables. You can create a table in org-mode as simple as creating the first line with pipes between each item, and then tab for the next cell or line. Formulas are also pretty simple. Then exporting to a blog turns that into a nice HTML table for you.

For instance, here’s the table I’ve been using to track my garden harvest so far this year, as it looks in org-mode as of today:

| date             | harvest      | grams | pounds | price | total $ |
|------------------+--------------+-------+--------+-------+---------|
| [2018-04-24 Tue] | asparagus    |   572 |   1.26 |  3.00 |    3.78 |
| [2018-04-26 Thu] | asparagus    |   556 |   1.22 |  3.00 |    3.66 |
| [2018-04-28 Sat] | asparagus    |   663 |   1.46 |  3.00 |    4.38 |
| [2018-04-30 Mon] | asparagus    |   508 |   1.12 |  3.00 |    3.36 |
| [2018-05-02 Wed] | asparagus    |   488 |   1.07 |  3.00 |    3.21 |
| [2018-05-05 Sat] | asparagus    |   460 |   1.01 |  3.00 |    3.03 |
| [2018-05-08 Tue] | asparagus    |   684 |   1.50 |  3.00 |    4.50 |
| [2018-05-08 Tue] | green onions |   128 |   0.28 |  2.00 |    0.56 |
| [2018-05-08 Tue] | marshmallow  |   100 |   0.22 |  1.00 |    0.22 |
| [2018-05-12 Sat] | asparagus    |  1066 |   2.34 |  3.00 |    7.02 |
| [2018-05-12 Sat] | lettuce      |   150 |   0.33 |  1.00 |    0.33 |
| [2018-05-15 Tue] | asparagus    |   736 |   1.62 |  3.00 |    4.86 |
| [2018-05-20 Tue] | asparagus    |   686 |   1.51 |  3.00 |    4.53 |
| [2018-05-20 Tue] | lettuce      |   150 |   0.33 |  1.00 |    0.33 |
| [2018-05-22 Tue] | asparagus    |   251 |   0.55 |  3.00 |    1.65 |
|------------------+--------------+-------+--------+-------+---------|
| Totals           |              |  7198 |  15.82 |  2.53 |   40.02 |
#+TBLFM: $4=$3/455;%.2f::$6=$4*$5;%.2f::$5=$5;%.2f:: @19$3=vsum(@4..@-1)::@19$5=vmean(@4..@-1);%.2f

The cryptic stuff at the bottom is a list of formulas to do things like convert grams to pounds and calculate and total the prices, so it stays up to date whenever I add lines.

And here’s how it looks in the web page as exported through ox-hugo, with no tinkering except to set a few general CSS table styles:

date harvest grams pounds price total $
[2018-04-24 Tue] asparagus 572 1.26 3.00 3.78
[2018-04-26 Thu] asparagus 556 1.22 3.00 3.66
[2018-04-28 Sat] asparagus 663 1.46 3.00 4.38
[2018-04-30 Mon] asparagus 508 1.12 3.00 3.36
[2018-05-02 Wed] asparagus 488 1.07 3.00 3.21
[2018-05-05 Sat] asparagus 460 1.01 3.00 3.03
[2018-05-08 Tue] asparagus 684 1.50 3.00 4.50
[2018-05-08 Tue] green onions 128 0.28 2.00 0.56
[2018-05-08 Tue] marshmallow 100 0.22 1.00 0.22
[2018-05-12 Sat] asparagus 1066 2.34 3.00 7.02
[2018-05-12 Sat] lettuce 150 0.33 1.00 0.33
[2018-05-15 Tue] asparagus 736 1.62 3.00 4.86
[2018-05-20 Sun] asparagus 686 1.51 3.00 4.53
[2018-05-20 Sun] lettuce 150 0.33 1.00 0.33
[2018-05-22 Tue] asparagus 251 0.55 3.00 1.65
Totals 7198 15.82 2.53 40.02
  • price notes
    • asparagus price from Mill Creek Farm in season
    • green onions guessed from online
    • no idea on marshmallow, so plugged in $1
    • have to look up lettuce price too