w:tcMar (Table Cell Margins)
Overrides the default table cell margins for an individual cell, specifying padding on each side independently.
Description
w:tcMar sets cell-specific padding (the space between the cell border and the cell content). It overrides the table-level default cell margins (w:tblCellMar in w:tblPr) for the cell it belongs to.
It is defined in ECMA-376 Part 1 §17.4.69.
Each side is specified by a child element with w:w (amount) and w:type (unit) attributes.
Child Elements
| Element | Description |
|---|---|
w:top |
Top padding. |
w:left |
Left (leading) padding. |
w:bottom |
Bottom padding. |
w:right |
Right (trailing) padding. |
Each child uses the same attribute set as w:tblCellMar children:
| Attribute | Type | Description |
|---|---|---|
w:w |
xsd:integer |
Amount of padding. |
w:type |
ST_TblWidth |
dxa (twips), nil (no padding). |
Examples
<!-- Override cell margins: 144 twips (0.1 inch) on all sides -->
<w:tc>
<w:tcPr>
<w:tcMar>
<w:top w:w="144" w:type="dxa"/>
<w:left w:w="144" w:type="dxa"/>
<w:bottom w:w="144" w:type="dxa"/>
<w:right w:w="144" w:type="dxa"/>
</w:tcMar>
</w:tcPr>
<w:p><w:r><w:t>Padded cell</w:t></w:r></w:p>
</w:tc>
using DocumentFormat.OpenXml.Wordprocessing;
var tcPr = new TableCellProperties(
new TableCellMargin(
new TopMargin { Width = "144", Type = TableWidthUnitValues.Dxa },
new LeftMargin { Width = "144", Type = TableWidthUnitValues.Dxa },
new BottomMargin { Width = "144", Type = TableWidthUnitValues.Dxa },
new RightMargin { Width = "144", Type = TableWidthUnitValues.Dxa }
)
);
Notes
- 1440 twips = 1 inch; 144 twips = 0.1 inch; 113 twips ≈ 2 mm.
- Omitting a side child element means that side inherits the table default margin.
- Use
w:type="nil"to set a side’s padding to zero.