Skip to main content

Tables

Tables organize content into rows and columns. Each cell accepts any content node — paragraphs, headings, lists, columns, images, SVG, barcodes, even nested tables — and can combine a text label with a co-located block (for example a caption above an image or nested table), following HTML5 <td> flow-content semantics. Tables can also be populated dynamically from data.

The fixture below walks through every common edge case in one place — auto-widths, proportional widths, float weights, cell-count vs. widths-length mismatches, variable row lengths, empty cells, colspan / rowspan, nesting, and long-content wrapping. Open it before reading the rest if you just want to see how tables behave.

Basic structure​

{
"table": {
"widths": [3, 2, 2],
"rows": [
[{ "p": "Column 1" }, { "p": "Column 2" }, { "p": "Column 3" }],
[{ "p": "Row 2, Col 1" }, { "p": "Row 2, Col 2" }, { "p": "Row 2, Col 3" }]
]
}
}

Properties​

PropertyTypeRequiredDescription
widthsnumber[]NoRelative column width proportions. Absent, the columns are equal (under tableLayout: auto, sized to their content)
rowsarray[]Unless sourceArray of rows, where each row is an array of cell content elements
stylestringNoThe named style of the table. Absent, the built-in table style (see Table-level styling)
captionstringNoA caption announced with the table, such as "Fee schedule"; markup allowed. Placed by the style's captionSide (above, by default) and tagged as the table's caption
rolestringNodata (default): the table reads by row and column. presentation: a layout grid, such as a form, whose cells read in order with no table announced
sourcestringNoA $data array the rows are made from (see Data-driven tables)
mapstring[]NoFor each column, the field of a source element that fills it; needs source

Column widths​

The widths array defines relative column proportions, not absolute pixel values. The available page width is divided according to these ratios.

"widths": [1, 1, 1]

Three equal-width columns.

"widths": [3, 1, 1]

The first column is three times wider than the second and third.

"widths": [4, 1, 1, 1]

Four columns where the first takes up about 57% of the width.

Rows​

Each row is an array of content elements. A row shorter than the grid leaves blank slots; a row count that does not match widths is reported.

Cell types​

Each cell in a row is a content element. Tables support three cell types for semantic clarity:

TypePurposeExample
thTable header cell, drawn in the built-in cellHeader style: plain until the document defines a style of that name{ "th": "Product" }
tdTable data cell — regular content{ "td": "$12,500" }
pGeneral paragraph — also works as a cell, most flexible{ "p": "[b]Bold text[/b]" }

All three types accept the same style property and inline formatting tags. Use th and td for semantic structure.

Header cells (th)​

Header rows are the leading rows made entirely of th cells: they repeat at the top of every page the table crosses (the style key repeatHeader, default true) and are tagged as the table's head. A row of styled p cells is a body row, whatever it looks like.

[
{ "th": "Product", "style": "th" },
{ "th": "Qty", "style": "th" },
{ "th": "Price", "style": "th" }
]

Data cells (td)​

[
{ "td": "Cloud Platform License", "style": "td" },
{ "td": "5", "style": "td" },
{ "td": "$2,400", "style": "td" }
]

Shortcodes in cells​

All cell types (th, td, p, h1–h6) support the full range of Shortcodes — images, barcodes, bold, color, etc.:

[
{ "th": "[image, images/logo.png, 60|20] Company", "style": "th" },
{ "td": "[barcode, qrcode, SF-20260330, 50|50]", "style": "td" },
{ "p": "[color, #27AE60][b]Active[/b][/color]" }
]

List cells​

[
{ "p": "Features" },
{
"ul": {
"li": [
{ "p": "Real-time tracking" },
{ "p": "Multi-carrier support" }
]
}
}
]

Table-level styling​

A table that states nothing is drawn with collapsed borders, a 0.5pt line between every pair of cells and round the outside, cells padded by one CSS pixel (0.75pt) each side, and fixed column widths. The table's style changes that, and its text keys (font, size, colour) reach every cell, under the cell's own style.

Apply a named style to the table itself (separate from cell styles). border: "none" removes the default lines:

{
"table": {
"style": "borderless",
"widths": [1, 1],
"rows": [[{ "td": "Item" }, { "td": "Amount" }]]
}
}

With the style defined as:

"borderless": { "border": "none" }

The style keys a table reads beyond the box keys every block takes:

Style keyValuesWhat it does
tableLayoutfixed (default), autofixed keeps the declared widths and wraps text inside them; auto sizes the columns to their content, no wider than the table wants. Under auto, stated widths become percentage columns
borderCollapsecollapse (default), separatecollapse: neighbouring cells share one border. separate: each cell draws its own, spaced by borderSpacing
borderSpacinga length, or [across, down]Space between separate cells. Absent under separate, 2 CSS pixels (1.5pt); [0, "5pt"] makes rows stand apart as strips
captionSidetop (default), bottomWhere the caption is drawn and announced. A bottom caption is drawn once, under the last row
repeatHeadertrue, falseWhether the header rows repeat at the top of every page the table crosses; default true
nthChild, nthLastChild, firstChild, lastChilda block of style keys per positionStyles the table's rows by position, as CSS's :nth-child(): the cells of each picked row take those keys, under their own

Zebra rows​

nthChild on the table's style shades every other row with no per-row style. The rows are counted among the body rows: the header rows are not counted. See Structural selectors for the An+B forms.

{
"document": {
"styles": {
"ledger": {
"nthChild": { "even": { "backgroundColor": "#F1F5F9" } },
"lastChild": { "fontWeight": "bold" }
}
},
"content": [
{
"table": {
"style": "ledger",
"caption": "Table 1: Shipments this week",
"widths": [3, 2, 1],
"rows": [
[{ "th": "Route" }, { "th": "Carrier" }, { "th": "Days" }],
[{ "td": "Dakar - Accra" }, { "td": "ShipForge Express" }, { "td": "3" }],
[{ "td": "Lagos - Nairobi" }, { "td": "Pan-Africa Freight" }, { "td": "5" }],
[{ "td": "Abidjan - Lomé" }, { "td": "Coastal Lines" }, { "td": "2" }],
[{ "td": "Total" }, { "td": "" }, { "td": "10" }]
]
}
}
]
}
}

The second and fourth body rows are shaded, and the last row, the total, is bold.

Built-in table styles​

Three style names are the engine's own. Defining one in styles restyles every table that names no style of its own:

NameApplies to
tableEvery table with no style
cellEvery td or p cell with no style
cellHeaderEvery th cell with no style; plain until the document defines it
{
"document": {
"styles": {
"cellHeader": { "fontWeight": "bold", "color": "#FFFFFF", "backgroundColor": "#1E3A5F", "padding": 4 },
"cell": { "padding": 4 }
},
"content": [
{
"table": {
"rows": [
[{ "th": "Code" }, { "th": "Item" }],
[{ "td": "A-1" }, { "td": "Pallet wrap" }]
]
}
}
]
}
}

An empty styled cell​

A cell written as a style alone, { "style": "name" }, is an empty cell drawn in that style: a shaded spacer, a struck-out slot. A cell's style is always the cell's own box, whatever the cell holds.

[{ "td": "Saturday" }, { "style": "closed" }, { "style": "closed" }]

The table's own box​

A table's style draws a box of its own around the grid: border, borderRadius, backgroundColor and outline as on any block.

  • With collapsed borders, the table's border and its edge cells' borders meet on one line, and the wider wins; where the table's is no wider, the cell keeps its own and the report says the table's was not drawn. How two cells' borders settle the line between them is on Borders.
  • With separate borders, the table draws its own border, rounded corners and background, with the cells standing inside it.
  • An outline goes round the table without taking room.
  • The caption stands outside the table's box and takes none of it.
{
"document": {
"styles": {
"card": {
"borderCollapse": "separate",
"borderSpacing": 4,
"border": "1pt solid #B91C1C",
"borderRadius": 6,
"backgroundColor": "#FEFCE8"
}
},
"content": [
{
"table": {
"style": "card",
"rows": [
[{ "th": "Code" }, { "th": "Pack" }, { "th": "Price" }],
[{ "td": "CR-20" }, { "td": "Box of 20" }, { "td": "$14.00" }]
]
}
}
]
}
}

A table's style also takes float and clear (the table moves to one edge and the text after it runs past its side), justifySelf for a table narrower than its container, and position (relative or fixed). The keys are on Box model.

Styling table cells​

Apply named styles to individual cell elements for formatting control.

Header row styling​

{
"document": {
"styles": {
"tableHeader": {
"fontSize": 10,
"fontWeight": "bold",
"color": "#FFFFFF",
"backgroundColor": "#2D3A4A",
"padding": 6
},
"tableCell": {
"fontSize": 9,
"color": "#333333",
"padding": 4,
"borderBottom": "0.5pt solid #E0E0E0"
}
},
"content": [
{
"table": {
"widths": [3, 2, 2],
"rows": [
[
{ "th": "Route", "style": "tableHeader" },
{ "th": "Carrier", "style": "tableHeader" },
{ "th": "Transit Time", "style": "tableHeader" }
],
[
{ "p": "Dakar - Accra", "style": "tableCell" },
{ "p": "ShipForge Express", "style": "tableCell" },
{ "p": "3-5 days", "style": "tableCell" }
],
[
{ "p": "Lagos - Nairobi", "style": "tableCell" },
{ "p": "Pan-Africa Freight", "style": "tableCell" },
{ "p": "5-7 days", "style": "tableCell" }
]
]
}
}
]
}
}

Spanning cells — colspan and rowspan​

Not to be confused with [col, N]

colspan merges multiple table columns into one cell — same as HTML's <td colspan="3">. [col, N] is the Shortcode that splits one paragraph into N weighted horizontal segments inside a single cell (or anywhere in body text). Inverse operations. See Layout Shortcodes → Column splits for the segment splitter. The §11 example in the edge-case gallery shows the two used together — colspan: 4 merges a full row, and [col, 3][col, 1] splits its interior into a label and a right-flushed status badge.

These follow the HTML table model: colspan and rowspan are attributes on the cell itself, not entries in a style block. They control structure (how many columns or rows the cell occupies), so they live on the cell next to the cell's content — the same place HTML puts them on <td> and <th>.

{ "p": "FY Totals", "style": "totals", "colspan": 3 }

Default is 1 (no span). Outside a table cell they span nothing, and the engine reports it — colspan on a top-level paragraph is a warning.

Colspan — merge across columns​

{
"table": {
"widths": [1, 1, 1, 1],
"rows": [
[
{ "th": "Region", "style": "th" },
{ "th": "Q1", "style": "th" },
{ "th": "Q2", "style": "th" },
{ "th": "Q3", "style": "th" }
],
[
{ "p": "North", "style": "td" },
{ "p": "182", "style": "tdNum" },
{ "p": "201", "style": "tdNum" },
{ "p": "218", "style": "tdNum" }
],
[
{ "p": "FY Totals", "style": "tdTotal", "colspan": 3 },
{ "p": "601", "style": "tdNumTotal" }
]
]
}
}

The totals label occupies the first three columns; the numeric total fills the fourth.

Rowspan — merge across rows​

When a cell spans multiple rows, subsequent rows don't repeat that column. They declare only the remaining cells in the row; the engine slots them into the columns to the right of the merged cell.

{
"table": {
"widths": [1, 3],
"rows": [
[{ "th": "Status", "style": "th" }, { "th": "Description", "style": "th" }],
[{ "p": "ACTIVE", "style": "tdStatus", "rowspan": 3 }, { "p": "First entry — top of the merged group.", "style": "td" }],
[ { "p": "Second entry — same status, no repeat label.", "style": "td" }],
[ { "p": "Third entry — closes out the merged group.", "style": "td" }]
]
}
}

In DOCX the engine auto-inserts the vertical-merge continuation cells underneath the spanning cell, so the resulting Word document opens with a clean merge — you don't have to author placeholder cells yourself.

Both at once​

A header banner that's both wide and tall:

{ "p": "QUARTERLY REVIEW · Q1 2026", "style": "banner", "colspan": 4, "rowspan": 2 }

Why not in the style block?​

colspan / rowspan are structural — they decide the cell's grid footprint, not how the cell looks. Putting them on the cell keeps the style block focused on visual styling (and lets a single style be reused for both spanning and non-spanning cells without duplication). This mirrors HTML, where colspan="3" is an attribute on <td>, not a CSS property.

Nested tables​

A cell can contain another table, allowing for complex layouts.

{
"table": {
"widths": [1, 1],
"rows": [
[
{ "p": "[b]Sender[/b]" },
{ "p": "[b]Recipient[/b]" }
],
[
{
"table": {
"widths": [1, 2],
"rows": [
[{ "p": "Name:" }, { "p": "ShipForge Ltd" }],
[{ "p": "City:" }, { "p": "London, UK" }]
]
}
},
{
"table": {
"widths": [1, 2],
"rows": [
[{ "p": "Name:" }, { "p": "Meridian Logistics" }],
[{ "p": "City:" }, { "p": "Accra, Ghana" }]
]
}
}
]
]
}
}

Text label plus a block​

A cell can hold both a text label and a co-located block — the label renders first, the block directly below it. This works with any block: a nested table, a columns layout, a ul/ol, an image, or svg shapes.

{
"table": {
"widths": [1, 2],
"rows": [
[
{ "td": "Regional split", "style": "th" },
{
"p": "Revenue by region:",
"table": {
"widths": [2, 1],
"rows": [
[{ "td": "North" }, { "td": "$4,200" }],
[{ "td": "South" }, { "td": "$3,850" }]
]
}
}
],
[
{ "td": "Follow-ups", "style": "th" },
{
"p": "Before close:",
"ul": {
"li": [
{ "p": "Confirm Q4 targets" },
{ "p": "Send revised deck" }
]
}
}
]
]
}
}

Swap the nested table or ul for columns, an image, or an svg block to pair any block with a label. Containers nest to substantial depth — a table inside a columns inside a list item, and so on.

Using inline formatting in cells​

Cells support the full range of inline formatting tags.

[
{ "p": "[color, #27AE60][b]Delivered[/b][/color]" },
{ "p": "[color, #E74C3C][b]Delayed[/b][/color]" },
{ "p": "[color, #F39C12][b]In Transit[/b][/color]" }
]

Across pages​

A table runs on across as many pages as it needs, and breaks between rows, never inside one:

  • The header rows are drawn again at the top of every page the table crosses, unless the table's style sets repeatHeader to false. They are stated once in the structure a screen reader follows; the repeats are page furniture.
  • A row that does not fit in the room left moves to the next page whole. A row taller than a page runs past the page's bottom edge.
  • Rows joined by a rowspan move as one group, so a spanning cell is never cut and its text is drawn once.
  • A nested table is carried whole by the row that holds it.
  • The table's border is drawn closed on every page it crosses, since no row is cut: boxDecorationBreak has nothing to slice, and clone on a table is reported with a NOTICE.
  • A caption above the table is drawn once, above its first row; a caption below is drawn once, under its last row.
  • breakInside: "avoid" on the table's style keeps the whole table on one page when it fits on one; breakBefore and breakAfter force a page break around it.

See Page breaks for the break keys.

Data-driven tables​

Tables can be populated dynamically from data, with source and either map or template rows. See Data Source for full details.

Basic Data Binding​

{
"table": {
"source": "$data.items",
"map": ["description", "qty", "amount"],
"widths": [3, 1, 1],
"rows": [
[
{ "th": "Description", "style": "th" },
{ "th": "Qty", "style": "th" },
{ "th": "Amount", "style": "th" }
]
]
}
}

The source path points to an array in your data object. The map array specifies which keys from each object become cell values, mapped left-to-right to columns. The leading th rows are kept as the header; the data rows follow them.

$item.* templating in map​

Instead of simple key names, map entries can be template strings that compose values from multiple fields:

{
"table": {
"source": "$data.lineItems",
"map": ["$item.sku", "$item.description", "$item.qty × $item.unit", "CAD $item.subtotal"],
"widths": [2, 3, 2, 2],
"rows": [
[
{ "th": "SKU", "style": "th" },
{ "th": "Description", "style": "th" },
{ "th": "Quantity", "style": "th" },
{ "th": "Subtotal", "style": "th" }
]
]
}
}

The third column composes "$item.qty × $item.unit" into values like "12 × box". The fourth column prepends a currency prefix: "CAD 1,450.00".

Template rows with $item​

The other way to write it, in place of map: write the row itself, with $item tokens in its cells. A row that carries an $item token is a template, drawn once per element of source, where it stands; a row that carries none is drawn once. Because the cells are written in full, a generated cell can be a th, carry a style, a colspan, an image or a barcode, and its style can itself be a token.

{
"table": {
"source": "$data.inspections",
"widths": [1, 4, 2],
"rows": [
[{ "th": "#" }, { "th": "Equipment" }, { "th": "Risk" }],
[{ "td": "$item.NUMBER" }, { "td": "$item.name" }, { "td": "$item.risk", "style": "$item.risk" }],
[{ "td": "$item.COUNT items inspected", "colspan": 3 }]
]
}
}
TokenValue
$item.fieldThe field of the element being drawn
$item.NUMBERThe element's position, from 1
$item.COUNTHow many elements source holds. A row whose only token is $item.COUNT is not a template: it is drawn once, as a summary row

Template rows written next to each other repeat as a group, so an element can make two rows (a line and its note) that stay together. A table gives map or template rows, never both: one declaring both is an error. See Data Source for empty sources and nested bindings.

Complete example: expense report​

Template:

{
"document": {
"styles": {
"title": { "fontSize": 16, "fontWeight": "bold" },
"th": {
"fontSize": 9, "fontWeight": "bold", "color": "#FFFFFF", "backgroundColor": "#1A1A2E",
"paddingTop": 5, "paddingRight": 8, "paddingBottom": 5, "paddingLeft": 8
},
"td": {
"fontSize": 9, "color": "#333333",
"paddingTop": 4, "paddingRight": 8, "paddingBottom": 4, "paddingLeft": 8,
"borderBottom": "0.5pt solid #E0E0E0"
},
"total": { "fontSize": 11, "fontWeight": "bold", "marginTop": 8 }
},
"content": [
{ "p": "Expense Report — $data.report.period", "style": "title" },
{ "p": "Employee: $data.employee.name | Department: $data.employee.department" },
{
"table": {
"source": "$data.expenses",
"map": ["$item.date", "$item.description", "$item.category", "$data.currency $item.amount"],
"widths": [2, 3, 2, 2],
"rows": [
[
{ "th": "Date", "style": "th" },
{ "th": "Description", "style": "th" },
{ "th": "Category", "style": "th" },
{ "th": "Amount", "style": "th" }
]
]
}
},
{ "p": "Total: $data.currency $data.total", "style": "total" }
]
}
}

Data:

{
"report": { "period": "Q1 2026" },
"employee": { "name": "Sarah Mitchell", "department": "Engineering" },
"currency": "USD",
"expenses": [
{ "date": "Jan 15", "description": "Conference registration", "category": "Training", "amount": "850.00" },
{ "date": "Jan 16", "description": "Flight YYZ → SFO", "category": "Travel", "amount": "1,240.00" },
{ "date": "Jan 17", "description": "Hotel (3 nights)", "category": "Accommodation", "amount": "960.00" },
{ "date": "Jan 18", "description": "Team dinner", "category": "Meals", "amount": "185.00" }
],
"total": "3,235.00"
}

Expected result:

DateDescriptionCategoryAmount
Jan 15Conference registrationTrainingUSD 850.00
Jan 16Flight YYZ → SFOTravelUSD 1,240.00
Jan 17Hotel (3 nights)AccommodationUSD 960.00
Jan 18Team dinnerMealsUSD 185.00

Note how "$data.currency $item.amount" in the map mixes a document-level $data value with per-row $item values — the currency prefix comes from the root data, while the amount comes from each expense row.

In DOCX​

The Word output writes a table on the same grid as the PDF:

  • tableLayout becomes Word's fixed or autofit layout.
  • The leading th rows are a header Word repeats on every page; every row is kept from splitting across pages, as in the PDF. A row taller than a page cannot be kept so, and is written splittable and reported.
  • A rowspan becomes a vertical merge, with the continuation cells written for you.
  • Under borderCollapse: separate, a table's own border, rounded corners and background are drawn as one shape behind the grid. A different down spacing in borderSpacing is not carried, and the report says so.
  • A table's background is carried by its cells. Where it shows in the table's padding, a shape draws it there too.
  • role: "presentation" has no Word form: the table is written as a table, and the report says so.