A table is w:tbl: its properties, then a grid of column widths, then rows.
Each row holds cells, and each cell holds block-level content, so a table can contain
paragraphs, lists and further tables.
An example
<w:tbl>
<w:tblPr>
<w:tblStyle w:val="TableGrid"/>
<w:tblW w:w="5000" w:type="pct"/>
</w:tblPr>
<w:tblGrid>
<w:gridCol w:w="2880"/>
<w:gridCol w:w="2880"/>
</w:tblGrid>
<w:tr>
<w:tc>
<w:tcPr><w:gridSpan w:val="2"/></w:tcPr>
<w:p><w:r><w:t>A heading across both columns</w:t></w:r></w:p>
</w:tc>
</w:tr>
<w:tr>
<w:tc><w:p><w:r><w:t>Left</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>Right</w:t></w:r></w:p></w:tc>
</w:tr>
</w:tbl>
A cell must end with a paragraph, even when it holds only a nested table.
Table properties: w:tblPr
| Element | Meaning |
|---|---|
w:tblStyle | A table style, by style ID. |
w:tblW | Preferred width: w:w and w:type (auto, dxa in twips, or pct). |
w:jc | Alignment of the whole table. |
w:tblInd | Indent from the leading margin. |
w:tblBorders | Borders: w:top, w:left, w:bottom, w:right, w:insideH, w:insideV. |
w:tblLayout | w:type: fixed or autofit. |
w:tblCellMar | Default cell margins. |
w:tblLook | Which parts of the table style apply: first row, last row, first column and so on. |
w:tblCaption, w:tblDescription | Alternative text for the table. |
w:tblPrChange | The previous properties, under tracked changes. |
The grid
w:tblGrid lists one w:gridCol for each column of the table, with
its width in twips. Cells line up against the grid: a cell that spans several columns
gives the number in w:gridSpan.
Rows and cells
w:tr can hold w:trPr, then w:tc cells. Rows and
cells can also be wrapped in a content control (w:sdt) or
w:customXml.
| Element | In | Meaning |
|---|---|---|
w:trHeight | w:trPr | Row height: w:val and w:hRule (auto, atLeast, exact). |
w:tblHeader | w:trPr | Repeat the row at the top of each page. |
w:cantSplit | w:trPr | Do not break the row across pages. |
w:ins, w:del | w:trPr | The row is a tracked insertion or deletion. |
w:tcW | w:tcPr | Preferred cell width. |
w:gridSpan | w:tcPr | The cell spans this many grid columns. |
w:vMerge | w:tcPr | Part of a vertically merged cell, below. |
w:tcBorders, w:shd, w:vAlign | w:tcPr | Borders, shading and vertical alignment. |
w:noWrap, w:textDirection | w:tcPr | No wrapping; the direction of the text. |
Merged cells
Horizontal merges are w:gridSpan on one cell. Vertical merges use
w:vMerge: the top cell has w:val="restart", and the cells below
have the element with no w:val, meaning “continue”. A continued cell is still
written with its own content, which is usually one empty paragraph.
<w:tr>
<w:tc><w:tcPr><w:vMerge w:val="restart"/></w:tcPr>
<w:p><w:r><w:t>Spans two rows</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>Row one</w:t></w:r></w:p></w:tc>
</w:tr>
<w:tr>
<w:tc><w:tcPr><w:vMerge/></w:tcPr>
<w:p/></w:tc>
<w:tc><w:p><w:r><w:t>Row two</w:t></w:r></w:p></w:tc>
</w:tr>