table directive#
The table directive creates simple data tables from comma-separated content. It supports transposition, per-column placement, inline math, and ellipsis expansion — making it ideal for textbook-style value tables.
Basic usage#
A table with labelled columns and rows of values:
:::{table}
labels: $x$, $f(x)$, $g(x)$
1, 2, 3
4, 5, 6
7, 8, 9
:::
| $x$ | $f(x)$ | $g(x)$ |
|---|---|---|
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 9 |
Syntax overview#
:::{table}
---
transpose:
width: 80%
align: center
---
labels: x, y, z
placement: center, right, left
1, 2, 3
4, 5, 6
:::
Content format#
The first
labels:line defines the column (or row) headers.Each subsequent non-empty line is a comma-separated data row.
placement:sets per-column text alignment (left,center,right).width:andalign:can appear in either front-matter options or the content body.
Options#
Option |
Meaning |
|---|---|
|
Swap rows and columns so labels become row headers |
|
CSS width of the table frame (e.g. |
|
Horizontal placement of the table: |
|
Extra CSS classes |
|
Stable anchor / reference name |
Examples#
Transposed table#
When :transpose: is set, labels become row headers instead of column headers:
:::{table}
---
transpose:
---
labels: $x$, $f(x)$
-2, 4
-1, 1
0, 0
1, 1
2, 4
:::
| $x$ | -2 | -1 | 0 | 1 | 2 |
|---|---|---|---|---|---|
| $f(x)$ | 4 | 1 | 0 | 1 | 4 |
Column alignment#
Use placement: to control how each column is aligned. The ellipsis ... repeats the preceding value for all remaining columns:
:::{table}
labels: Term, Formula, Value
placement: left, center, ...
$a_1$, $2 \cdot 1$, 2
$a_2$, $2 \cdot 2$, 4
$a_3$, $2 \cdot 3$, 6
:::
| Term | Formula | Value |
|---|---|---|
| $a_1$ | $2 \cdot 1$ | 2 |
| $a_2$ | $2 \cdot 2$ | 4 |
| $a_3$ | $2 \cdot 3$ | 6 |
Ellipsis rows and cells#
Use ... as a full row to insert a vertical ellipsis, or inside a cell for horizontal ellipsis:
:::{table}
labels: $n$, $a_n$
1, 2
2, 4
...
10, 20
:::
| $n$ | $a_n$ |
|---|---|
| 1 | 2 |
| 2 | 4 |
| $\vdots$ | |
| 10 | 20 |
Custom width and alignment#
:::{table}
---
width: 60%
align: left
---
labels: $x$, $y$
0, 0
1, 1
2, 4
:::
| $x$ | $y$ |
|---|---|
| 0 | 0 |
| 1 | 1 |
| 2 | 4 |
Tips#
Commas inside math (
$...$) and quoted strings are preserved — they do not split cells.An ellipsis-only row (
...) produces a \(\vdots\) marker in the first column (or the full row when transposed).The
widthoption accepts CSS units:%,px,em,rem, and keywords likeautoorfit-content.