Tables
Tables in the creator package are built by column count and filled cell by cell.
c.NewTable(n) fixes the number of columns; every NewCell call adds the next cell,
left to right, starting a new row once the current one is full. Cells are not
addressable by coordinates, so the order in which you add them is the layout.
table := c.NewTable(3)
cell := table.NewCell()
if err := cell.SetContent(p); err != nil {
return err
}
if err := c.Draw(table); err != nil {
return err
}Almost everything else is a property of the cell rather than the table. Borders, background color, alignment and indent are set per cell, which is why most examples wrap cell creation in a small local helper. The table itself owns only what concerns the whole grid: the column count, header rows and row wrapping.
Content goes into a cell through SetContent, which takes any drawable. That
includes paragraphs, images, divisions and other tables, and it is what makes the
nested layouts in these guides possible.
Where to look
| Guide | Covers |
|---|---|
| Simple | Alignment, text wrapping and overflow. |
| Styling | Cell borders and background colors. |
| Column span | Cells covering several columns. |
| Row span | Cells covering several rows. |
| Headers | Header rows repeated across pages, images in cells. |
| Row wrap | What happens to a row that does not fit on the page. |
| Subtables | Composing a table from smaller tables. |
| Division layout | Multi-column page layouts using divisions in cells. |
If you are choosing between a table and the newer Grid component, see the
grid guides. Grid uses an explicit rows and cells structure rather than a
running cell count, which makes spans easier to reason about and turns an overfull
row into an error instead of a silent reflow.