tables · 13m

Tables as structured calculations

Type a row, press TAB, and Org turns plain pipes into an aligned, computable table.

Type | Name | Score | and press TAB. Org aligns the columns and treats the pipes as a real table:

| Name  | Hours | Rate | Total |
|-------+-------+------+-------|
| Alice |   2.5 |   80 |   200 |
| Bob   |     3 |   70 |   210 |
#+TBLFM: $4=$2*$3

The #+TBLFM: line holds formulas. $4=$2*$3 says column 4 is column 2 times column 3.

Moving and editing

TAB and S-TAB move among cells. M-left/M-right move columns; M-up/M-down move rows. C-c - inserts a horizontal rule. C-c ^ sorts. C-c C-c recalculates at point; C-u C-c C-c recalculates the whole table.

References

Formula references include $2 (column 2), @3 (row 3), @2$4 (one cell), and ranges such as @2$2..@>$2. @> means the last row. Org accepts Calc syntax or Lisp formulas.

Name a table when Babel should consume it:

#+name: monthly-hours
| Month | Hours |
|-------+-------|
| Jan   |    18 |
| Feb   |    21 |

Derived columns and a real total

A consulting report can compute subtotal, tax, and a grand total in one formula line:

#+name: invoice-lines
| Description       | Hours | Rate | Subtotal | Tax | Total |
|-------------------+-------+------+----------+-----+-------|
| Architecture      |   3.5 |  120 |          | .1  |       |
| Deployment review |     2 |  120 |          | .1  |       |
|-------------------+-------+------+----------+-----+-------|
| Total             |       |      |          |     |       |
#+TBLFM: $4=$2*$3;%.2f::$6=$4*(1+$5);%.2f::@>$6=vsum(@2$6..@-1$6);%.2f

Here $4 and $6 compute per-row values, @>$6 fills the last-row total, and @-1 means the row above that last row. The %.2f directives keep two decimals. Recalculate, then verify a sample by hand: a syntactically valid formula can still encode the wrong business rule.

Where tables stop

Use Org tables for small, inspectable datasets, estimates, inventories, and report inputs. Remote references and named tables can build dashboards, but hidden dependencies make a document harder to move. Keep the source table near its consumer or document every dependency. For financial, regulated, or high-volume work, use a tested spreadsheet or database and import only a summary.

Summary. Org tables are small spreadsheets built from text: alignment, cell navigation, and a formula line drive derived columns and totals. They are ideal for inspectable datasets and honest about where a real spreadsheet or database belongs.

Exercises

  • Basic: Create a three-row table, align it with `TAB`, and sort it with `C-c ^`.
  • Practical: Build an invoice or study-hours table with a subtotal and tax column, then validate one row by hand against the formula.
  • Advanced: Add a last-row total using `@>$6=vsum(@2$6..@-1$6)`, recalculate, and confirm the aggregate matches the rows above it.