RTF has no table group. A table is a run of rows, and a row is a run of paragraphs
that are split into cells. \trowd starts a row’s definition,
\cell ends each cell and \row ends the row. Every paragraph in
a row has \intbl, set or inherited. A row may reuse the previous row’s
definition. Lengths are in twips.
Grammar
<row> = (<tbldef> <cell>+ <tbldef> \row) | (<tbldef> <cell>+ \row) | (<cell>+ <tbldef> \row)
<cell> = (<nestrow>? <tbldef>?) & <textpar>+ \cell
<nestrow> = <nestcell>+ '{\*' \nesttableprops <tbldef> \nestrow '}'
<nestcell> = <textpar>+ \nestcell
<tbldef> = \trowd \trgaph & <rowjust>? & <rowwrite>? & <rowtop>? & <rowbot>? & <rowleft>?
& <rowright>? & <rowhor>? & <rowvert>? & <rowpos>? & \trleft? & \trrh? \trhdr?
& \trkeep? & <rowwidth>? & <rowinv>? & \trautofit? & <rowspc>? & <rowpad>?
& \taprtl? <celldef>+
<rowjust> = \trql | \trqr | \trqc
<rowwrite> = \ltrrow | \rtlrow
<rowtop> = \trbrdrt <brdr> (and \trbrdrl, \trbrdrb, \trbrdrr, \trbrdrh, \trbrdrv likewise)
<rowpos> = <rowhorzpos> & <rowvertpos> & <rowwrap> & \tabsnoovrlp?
<rowwrap> = \tdfrmtxtLeft? & \tdfrmtxtRight? & \tdfrmtxtTop? & \tdfrmtxtBottom?
<rowhframe> = \tphmrg? | \tphpg? | \tphcol?
<rowhdist> = \tposx? | \tposnegx? | \tposxc? | \tposxi? | \tposxo? | \tposxl? | \tposxr?
<rowvframe> = \tpvmrg? | \tpvpg? | \tpvpara?
<rowvdist> = \tposy? | \tposnegy? | \tposyt? | \tposyil? | \tposyb? | \tposyc? | \tposyin | \tposyout
<rowwidth> = \trftsWidth & \trwWidth?
<rowinv> = (\trftsWidthB & \trwWidthB?)? & (\trftsWidthA & \trwWidthA?)?
<rowspc> = (\trspdl & \trspdfl?)? & (\trspdt & \trspdft?)? & (\trspdb & \trspdfb?)? & (\trspdr & \trspdfr?)?
<rowpad> = (\trpaddl & \trpaddfl?)? & (\trpaddt & \trpaddft?)? & (\trpaddb & \trpaddfb?)? & (\trpaddr & \trpaddfr?)?
<celldef> = (\clmgf? & \clmrg? & \clvmgf? & \clvmrg? <celldgu>? & <celldgl>? & <cellalign>? & <celltop>?
& <cellleft>? & <cellbot>? & <cellright>? & <cellshad>? & <cellflow>? & \clFitText?
& \clNoWrap? & <cellwidth>? & <cellpad>?) \cellx
<cellshad> = <cellpat>? \clcfpat? & \clcbpat? & \clshdng
<cellwidth> = \clftsWidth & \clwWidth?
<cellpad> = (\clpadl & \clpadfl?)? & (\clpadt & \clpadft?)? & (\clpadb & \clpadfb?)? & (\clpadr & \clpadfr?)?
A row definition has one <celldef>, ending in
\cellx, per cell, and the number of \cellx must equal the
number of \cell in the row. Word 97 wrote the definition at the start of
the row; Word 2000 writes it at the end, and a copy at the start for older readers. A
reader must not assume either place. For nested rows Word 2000 writes it only at the
end.
Rows, cells and nesting
| Control word | Meaning |
|---|---|
\trowd | Reset to the default row properties and start a row definition. |
\row | End of the row. |
\tcelld | Reset to the default cell properties. |
\cell | End of a cell. |
\cellxN | Right edge of the cell, including its half of the gap between cells, measured from the left edge of the column the table is in. Ends the cell’s definition. |
\trgaphN | Half the space between cells. |
\nestcell | End of a cell in a nested table. |
\nestrow | End of a row in a nested table. |
\nesttableprops | Destination: the definition of a nested row, written after its cells as {\*\nesttableprops … \nestrow}. |
\nonesttables | Destination: text for readers that do not understand nested tables, usually a \par to put each nested cell in its own paragraph. Readers that support nesting ignore it. |
\itapN | (Paragraph property) nesting depth of the paragraph: 1 in a table, 2 in a nested table. |
\clmgf | First cell of a range of horizontally merged cells. |
\clmrg | This cell is merged with the one before it. |
\clvmgf | First cell of a range of vertically merged cells. |
\clvmrg | This cell is merged with the one above it. |
Row properties
| Control word | Meaning |
|---|---|
\trleftN | Position of the table’s left edge relative to the left of its column. |
\trql | Row aligned to the left of the column. |
\trqr | Aligned to the right. |
\trqc | Centred. |
\trrhN | Row height: 0 fits the text, positive is a minimum, negative is exact. |
\trhdr | Header row: repeated at the top of every page the table runs onto. |
\trkeep | Do not split the row across pages. |
\trkeepfollow | Keep the row on the same page as the next row. |
\trautofitN | AutoFit: 0 off (default), 1 on. Preferred widths (\clwWidth, \trwWidth) override it. |
\taprtl | The table reads right to left. |
\rtlrow | Cells in the row run right to left. |
\ltrrow | Cells run left to right (default). |
Widths, padding and spacing
Word 2000 added preferred widths, padding (inner margins) and spacing between cells.
Each value has a companion word giving its unit; \cellx and
\trgaph are still written for older readers.
| Control word | Meaning |
|---|---|
\trwWidthN | Preferred row width; overrides \trautofit. |
\trftsWidthN | Unit of \trwWidth: see width units. With 1 (auto) there is no preferred width. |
\trwWidthBN | Width of an invisible cell before the first cell, used when rows have different widths. |
\trftsWidthBN | Unit of \trwWidthB; 0 means no invisible cell before. |
\trwWidthAN | Width of an invisible cell after the last cell. |
\trftsWidthAN | Unit of \trwWidthA; 0 means no invisible cell after. |
\clwWidthN | Preferred cell width; overrides \trautofit. |
\clftsWidthN | Unit of \clwWidth. |
\trpaddlN, \trpaddtN, \trpaddbN, \trpaddrN | Default left, top, bottom and right padding of the row’s cells. |
\trpaddflN, \trpaddftN, \trpaddfbN, \trpaddfrN | Their units: 0 ignore the padding and use \trgaph (Word 97 style); 3 twips. |
\clpadlN, \clpadtN, \clpadbN, \clpadrN | Left, top, bottom and right padding of one cell; override the row’s. |
\clpadflN, \clpadftN, \clpadfbN, \clpadfrN | Their units: 0 ignore and use \trgaph; 3 twips. |
\trspdlN, \trspdrN | Default left and right cell spacing. The space between two cells side by side is the right cell’s \trspdl plus the left cell’s \trspdr; Word writes them equal. |
\trspdtN, \trspdbN | Default top and bottom cell spacing, added in the same way between cells one above the other. |
\trspdflN, \trspdftN, \trspdfbN, \trspdfrN | Their units: 0 ignore the spacing; 3 twips. |
\clFitText | Fit the text in the cell by compressing each paragraph to the cell’s width. |
\clNoWrap | Do not wrap text in the cell. Only has an effect when the cell has no preferred width. |
Width units
Values of \trftsWidth, \trftsWidthB,
\trftsWidthA and \clftsWidth:
| N | Unit |
|---|---|
| 0 | None: ignore the width and use \cellx (Word 97 style). For B and A, no invisible cell. |
| 1 | Auto: no preferred width; the width word is usually not written. |
| 2 | Percentage, in fiftieths of a per cent (5,000 is 100%). |
| 3 | Twips. |
Positioned tables
A table that floats with text wrapped round it. Every row of the table must have the same values. The paragraphs in it also carry the matching frame words for older readers.
| Control word | Meaning |
|---|---|
\tdfrmtxtLeftN | Distance between the left of the table and the text round it (default 0). |
\tdfrmtxtRightN | Distance on the right (default 0). |
\tdfrmtxtTopN | Distance above (default 0). |
\tdfrmtxtBottomN | Distance below (default 0). |
\tabsnoovrlp | Do not overlap other tables or shapes with similar wrapping. |
\tphcol | Horizontal position relative to the column (default). |
\tphmrg | Relative to the margin. |
\tphpg | Relative to the page. |
\tposxN | N twips from the left of the reference. |
\tposnegxN | As \tposx, any negative value allowed. |
\tposxc | Centred horizontally. |
\tposxi | Inside. |
\tposxo | Outside. |
\tposxl | At the left. |
\tposxr | At the right. |
\tpvmrg | Vertical position relative to the top margin (default). |
\tpvpg | Relative to the top of the page. |
\tpvpara | Relative to the top left of the next paragraph that is not framed. |
\tposyN | N twips from the top of the reference. |
\tposnegyN | As \tposy, any negative value allowed. |
\tposyt | At the top. |
\tposyc | Centred vertically. |
\tposyb | At the bottom. |
\tposyil | In line. |
\tposyin | Inside. |
\tposyout | Outside. (The specification’s index lists it as \tposyoutv.) |
Borders
Each side word is followed by a border kind, width and colour, as for paragraph borders.
| Control word | Meaning |
|---|---|
\trbrdrt | Row border, top. |
\trbrdrl | Row border, left. |
\trbrdrb | Row border, bottom. |
\trbrdrr | Row border, right. |
\trbrdrh | Row border, inside horizontal. |
\trbrdrv | Row border, inside vertical. |
\clbrdrt | Cell border, top. |
\clbrdrl | Cell border, left. |
\clbrdrb | Cell border, bottom. |
\clbrdrr | Cell border, right. |
\cldglu | Diagonal line from top left to bottom right. |
\cldgll | Diagonal line from top right to bottom left. |
Cell shading, alignment and text flow
| Control word | Meaning |
|---|---|
\clshdngN | Shading in hundredths of a per cent. Written with the cell border words. |
\clbghoriz | Horizontal pattern. |
\clbgvert | Vertical pattern. |
\clbgfdiag | Forward diagonal pattern (\\\\). |
\clbgbdiag | Backward diagonal pattern (////). |
\clbgcross | Cross pattern. |
\clbgdcross | Diagonal cross pattern. |
\clbgdkhor | Dark horizontal pattern. |
\clbgdkvert | Dark vertical pattern. |
\clbgdkfdiag | Dark forward diagonal pattern. |
\clbgdkbdiag | Dark backward diagonal pattern. |
\clbgdkcross | Dark cross pattern. |
\clbgdkdcross | Dark diagonal cross pattern. |
\clcfpatN | Colour of the pattern lines (colour table index). |
\clcbpatN | Background colour of the cell (colour table index). |
\clvertalt | Text at the top of the cell (default). |
\clvertalc | Text centred vertically. |
\clvertalb | Text at the bottom. |
\cltxlrtb | Text flows left to right, top to bottom (default). |
\cltxtbrl | Right to left, top to bottom. |
\cltxbtlr | Left to right, bottom to top. |
\cltxlrtbv | Left to right, top to bottom, vertical. |
\cltxtbrlv | Top to bottom, right to left, vertical. |
Example
A two-by-two table with single borders, cells 1.5 inches wide, starting at the left margin:
\trowd\trgaph108\trleft-108
\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \cellx2052
\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \cellx4212
\pard\intbl A1\cell B1\cell \row
\pard\intbl A2\cell B2\cell \row
\pard\par
\trgaph108 leaves 108 twips of space each side of the text in a cell, so
\trleft-108 lines the text up with the margin. The cells end at 2,052 and
4,212 twips: 2,160 twips (1.5 inches) wide. The second row has no
\trowd and reuses the first row’s definition.
The specification also gives a complete Word 2000 example: a positioned table
(\tphmrg\tposxc\tposyc) of two rows, the first offset with an invisible
cell before it (\trftsWidthB3\trwWidthB504) and holding a nested table
(paragraphs with \itap2, cells ended by \nestcell, then
{\*\nesttableprops\trowd … \cellx2348\nestrow}{\nonesttables\par}), the
second offset with an invisible cell after it (\trwWidthA900). Each row
repeats its whole definition at its end inside {… \row }, as Word 2000
does.
Added after RTF 1.6
The RTF 1.9.1 specification (19 March 2008) adds these table words. “Flagged” is the Word version its control word index gives (– means none); none of these words is in the 1.6 specification, although some are flagged 2000.
Rows
| Control word | Flagged | Meaning |
|---|---|---|
\irowN | 2002 | Index of this row. |
\irowbandN | 2002 | Row index counted for banding: header rows are −1. |
\lastrow | 2002 | This is the last row of the table. |
\trauthN | 2002 | With revisions tracked: author of a change to the row’s properties, entry N of the revision table. |
\trdateN | – | Date of that change, as a DTTM value. |
\tbllkborder, \tbllkshading, \tbllkfont, \tbllkcolor, \tbllkbestfit | 2002 | Table AutoFormat applies to borders, shading, font, colour, best fit. |
\tbllkhdrrows, \tbllklastrow, \tbllkhdrcols, \tbllklastcol | 2002 | AutoFormat formats the header row, last row, first column, last column. |
\tbllknorowband, \tbllknocolband | 2007 | Do not apply row (column) banding conditional formatting. |
\trpadotN, \trpadobN, \trpadolN, \trpadorN | 2000 | Default top cell padding for the top row, bottom padding for the bottom row, left padding for the leftmost column, right padding for the rightmost column. |
\trpadoftN, \trpadofbN, \trpadoflN, \trpadofrN | 2000 | Their units: 0 null (use \trgaphN, Word 97 style), 3 twips. |
\trspotN, \trspobN, \trspolN, \trsporN | 2000 | Default top, bottom, left and right cell spacing for the outer rows and columns. |
\trspoftN, \trspofbN, \trspoflN, \trspofrN | 2000 | Their units: 0 null (ignore), 3 twips. |
\tblindN | 2007 | Indent added before the table’s leading edge (left in left-to-right tables), in the units of \tblindtypeN; 0 if missing. |
\tblindtypeN | 2007 | Units: 0 auto, 1 twips (default), 2 none (zero), 3 fiftieths of a percent; other values ignored. |
\trcbpatN, \trcfpatN | 2002 | Background and foreground colour of row shading. |
\trpatN | 2002 | Pattern of row shading. |
\trshdngN | 2002 | Percentage of row shading. |
\trbghoriz, \trbgvert, \trbgfdiag, \trbgbdiag, \trbgcross, \trbgdcross, \trbgdkhor, \trbgdkvert, \trbgdkfdiag, \trbgdkbdiag, \trbgdkcross, \trbgdkdcross | 2002 | Row shading pattern: horizontal, vertical, forward diagonal, backward diagonal, cross, diagonal cross, and the dark forms of each. |
Cells
| Control word | Flagged | Meaning |
|---|---|---|
\clsplN, \clsptN, \clspbN, \clsprN | 2000 | Left, top, bottom and right cell margin or padding, overriding \trspdlN and the rest. |
\clspflN, \clspftN, \clspfbN, \clspfrN | 2000 | Their units: 0 null (ignore), 3 twips. |
\clhidemark | 2007 | The end-of-cell mark does not count towards the row height; only printing characters do, so a row used as a border can be made very thin. |
\clins, \cldel | 2007 | After a document compare: the cell was inserted, or deleted (it stays in the structure but no longer exists). |
\clmrgd, \clmrgdr | 2007 | After a compare: the cell was merged with the cell above, or below. |
\clsplit, \clsplitr | 2007 | After a compare: the cell was split from the cell above, or below. |
\clinsauthN, \clinsdttmN | 2007 | Author and date of the cell insertion. |
\cldelauthN, \cldeldttmN | 2007 | Author and date of the cell deletion. |
\clmrgdauthN, \clmrgddttmN | 2007 | Author and date of the merge or split. |
\clshdrawnil | 2002 | No shading specified. |
\clshdngrawN, \clcfpatrawN, \clcbpatrawN | 2002 | Raw forms of \clshdngN, \clcfpatN and \clcbpatN, for use with table styles. |
\rawclbghoriz, \rawclbgvert, \rawclbgfdiag, \rawclbgbdiag, \rawclbgcross, \rawclbgdcross, \rawclbgdkhor, \rawclbgdkvert, \rawclbgdkfdiag, \rawclbgdkbdiag, \rawclbgdkcross, \rawclbgdkdcross | 2002 | Raw forms of the \clbg… shading patterns, for use with table styles. |
Table styles
Table styles came with Word 2002. They are defined in the style sheet as
{\*\tsN \tsrowd … ;} and allow conditional formatting, such as colouring
the first row. Formatting a user applies on top of a style is written with “raw”
words, which take priority over the ordinary ones that older readers still see. Any
older table formatting word may also be used in a style.
| Control word | Meaning |
|---|---|
\tscellwidthN, \tscellwidthftsN | Written but have no effect. |
\tscellpaddtN, \tscellpaddlN, \tscellpaddrN, \tscellpaddbN | Top, left, right and bottom cell padding. |
\tscellpaddftN, \tscellpaddflN, \tscellpaddfrN, \tscellpaddfbN | Their units: 0 auto, 3 twips. |
\tsvertalt, \tsvertalc, \tsvertalb | Cell vertical alignment: top, centre, bottom. |
\tsnowrap | No wrapping in cells. |
\tscellcfpatN, \tscellcbpatN | Foreground and background shading colour. |
\tscellpctN | Shading in hundredths of a percent. |
\tsbghoriz, \tsbgvert, \tsbgfdiag, \tsbgbdiag, \tsbgcross, \tsbgdcross, \tsbgdkhor, \tsbgdkvert, \tsbgdkfdiag, \tsbgdkbdiag, \tsbgdkcross, \tsbgdkdcross | Shading pattern: horizontal, vertical, forward diagonal (\\\\), backward diagonal (////), cross, diagonal cross, and dark forms. |
\tsbrdrt, \tsbrdrb, \tsbrdrl, \tsbrdrr | Top, bottom, left and right cell border. |
\tsbrdrh, \tsbrdrv | Inside horizontal and vertical borders. |
\tsbrdrdgl, \tsbrdrdgr | Diagonal borders, upper left to lower right and lower left to upper right. |
\tscbandshN | Rows in a row band. |
\tscbandsvN | Cells in a column band. |
All flagged 2002. Conditional parts of a style are further style entries with the
same handle that start with a position word (\tscfirstrow,
\tscbandhorzodd and so on, see the
paragraph page):
{\*\ts16\tsrowd\tscellcfpat7\tscellcbpat8\tscellpct10000\tsbrdrb\brdrs\brdrw15\brdrcf1
\tsbrdrdgl\brdrnil\tsbrdrdgr\brdrnil \b\i \tscfirstrow Table List 8;}
From the specification’s example: the first row of style 16, “Table List 8”, is shaded and has bold italic text.
Default table style for the document: \tsdN
(document properties);
the style a row or cell uses: \ytsN.
Source: Microsoft, Rich Text Format (RTF) Specification, version 1.9.1, 19 March 2008, sections “Table Definitions”, “Table Styles” and Appendix B; the PDF copy Microsoft keeps for its Open Specifications.