Tables

Tables

htmlbag supports the standard HTML table model: <table>, <thead>, <tbody>, <tfoot>, <tr>, <td>, <th>, plus <colgroup> / <col> for column-level styling.

Basic features

  • Cell borders, padding, background.
  • colspan and rowspan attributes.
  • Cell width via <col style="width: …"> or per-cell CSS.
  • Headers (<thead>) repeat at the top of each page when the table spans multiple pages.
  • Footers (<tfoot>) render once after the table’s last row. They are emitted as a separate row group and, in tagged PDFs, marked with a TFoot structure element so screen readers can distinguish summary rows from data rows. Per-page footer repetition is not yet implemented; the footer prints once below the final body row.
  • CSS structural selectors apply to row and cell elements, so alternating-row colors work via tr:nth-child(even) without explicit classes — see the zebra-table example.

Cell alignment

Horizontal alignment in a cell follows text-align on <td> / <th> or any ancestor element. Vertical alignment is controlled with vertical-align: top | middle | bottom on the cell or — for a whole column — on the <col> element. The value propagates down through the inheritable-style cascade, so setting vertical-align: top on the <table> itself affects every cell that doesn’t override it.

Multi-page tables and inserts

Tables that need to break across pages take a special path (outputTableRows) that places rows directly without going through the body buffer. As a consequence, multi-page tables are boundary-isolated:

  • The current page’s body buffer is shipped before the table starts.
  • After the last table row, the page is shipped before any further body content is buffered.

This means a <table> with <thead> repeating headers does not share a page with adjacent body content (there’s a hard page break on either side). Tables with no header repeat behave like normal block content and share pages freely.

Footnotes inside table cells

Footnotes inside table cells are extracted at table-build time and attached to the table’s VList. They land on the page where the table’s last row sits.

Floats inside table cells

Floats inside table cells (top or bottom) are extracted alongside footnotes and attached to the table VList. They behave like any other float — landing on the page where the table sits, in the appropriate top/bottom stack.