Simple tutorial for programmers — part 3
RTF – Working with Tables
Defining rows and cells, adding borders, controlling padding, and border style reference
This page builds on the first example. The original use case was a database report with three columns: a question column, a current-period comments column, and a last-period comments column, with rows for each question.
\cellx2880 places a cell boundary at exactly 2 inches from the left margin.
Basic table structure
Each row starts with \trowd and ends with \row. Within a row, cell boundaries are declared with \cellxN (the right edge of each cell in twips), and cell content ends with \intbl\cell. The example below creates one row with three cells, ending at 1000, 2000, and 3000 twips:
Rendered output
| cell 1 | cell 2 | cell 3 |
Auto-expanding row height
Unlike tabs, table rows automatically grow to fit their content. If one cell contains a long string, the entire row height expands to accommodate it:
Rendered output
| cell 1 | lots of text in cell two | cell 3 |
Adding cell borders
Border commands are placed before each \cellxN declaration. The four sides are top (\clbrdrt), left (\clbrdrl), bottom (\clbrdrb), and right (\clbrdrr). Follow each with a border style — \brdrs gives a plain single line:
Rendered output
| cell 1 | lots of text in cell two | cell 3 |
Cell padding with \trgaph
Without padding, text sits flush against the cell border. \trgaphN on the \trowd line sets the half-gap between cell content and borders. A value of 144 twips gives a comfortable 1/10" of breathing room:
Rendered output (with padding)
| cell 1 | lots of text in cell two | cell 3 |
Adding a second row
Repeat the \trowd…\row block for each additional row. Use \par and \pard between rows to reset paragraph state cleanly:
Rendered output
| cell 1 | lots of text in cell two | cell 3 |
| row 2 cell 1 | lots of text in row 2 cell two | row 2 cell 3 |
Border style reference
Instead of \brdrs (single line), a range of other border styles are available. The RTF command is applied to all four sides of the cell — for example, replacing \brdrs with \brdrdot gives a dotted border. Download the example .rtf file to see all styles rendered in a word processor.
| RTF command | Description | Preview |
|---|---|---|
| \brdrs | Single line | abc |
| \brdrdot | Dotted | abc |
| \brdrdb | Double thickness | abc |
| \brdrdash | Dashed | abc |
| \brdrdashsm | Small dashes | abc |
| \brdrdashd | Dot-dash | abc |
| \brdrdashdd | Dot-dot-dash | abc |
| \brdrtriple | Triple line | abc |
| \brdrtnthlg | Thick-thin (large) | abc |
| \brdrthtnlg | Thin-thick (large) | abc |
| \brdrtnthtnlg | Thin-thick-thin (large) | abc |
| \brdrwavy | Wavy | abc |
| \brdrdashdotstr | Striped | abc |
| \brdremboss | Embossed | abc |
| \brdrengrave | Engraved | abc |