1. Tables 🔗
NML support for tables is still very limited, though it is possible to build complex layouts like this one:
First column | Second column | |
Centered | B | C |
1 | 2 |
(1) Sample table
Given by the following code
:TABLE {sample_table} Sample table |
| **First column** |:hspan=2: **Second column** | |
|:align=center: Centered | B | C | |
|:hspan=2: 1 | 2 | |
When a line starts with | it is considered as the start of a table. Other |'s delimit the cells of a table row. You can also use :TABLE {refname} Title before the first line of the table, to make the table into a referenceable element. Tables declared like this are displayed as media.
2. Cell Properties 🔗
On each cell of a table, you may specify properties for the cell, row, column or table. Properties are specified between :'s at the start of a cell. It is not possible to redefine an already present property (e.g setting the table text-alignment twice). Below are the supported properties:
- Cells
- align The text-alignment of the cell
- hspan The horizontal span of the cell (1 if unset)
- vspan The vertical span of the cell (1 if unset)
- Rows Cells will inherit properties from their parent row
- align The text-alignment of the row
- rvspan The vertical span of the row (1 if unset)
- Columns Cells will inherit properties from their parent column
- chspan The horizontal span of the column (1 if unset)
- Table Each cell will inherit these properties
- align Text-alignment for the entire table
3. Tables to Lua 🔗
You can export a table to use it inside a lua snippet. Using :TABLE[export_as=table1] will make the table available to lua as nml.tables.table1.
Example:
Using Lua, you can perform computations on table rows, cells, etc.
Length | Occurences |
1.15 | 357 |
1.20 | 143 |
1.23 | 72 |
Average = 1.1725699300699
Which is given by:
1 | :TABLE[export_as=measures] |
2 | | Length | Occurences | |
3 | | 1.15 | 357 | |
4 | | 1.20 | 143 | |
5 | | 1.23 | 72 | |
6 | @<main |
7 | function weighted_average(table, i, j) |
8 | local weighted_sum = 0 |
9 | local total = 0 |
10 | for rowIndex, row in pairs(table) do |
11 | if rowIndex ~= 1 then |
12 | weighted_sum = weighted_sum + row[i] * row[j]; |
13 | total = total + row[j] |
14 | end |
15 | end |
16 | return weighted_sum / total |
17 | end |
18 | >@ |
19 | |
20 | Average = %<" weighted_average(nml.tables.measures, 1, 2)>% |
4. Current limitations 🔗
Current known limitations for tables, may change in the future:
- Referenceable elements cannot be referenced if defined inside of a table.
- Table layouts are limited and it is not possible to split a cell in half if it's parent column has a span of 2.