3. Tables
• Tables are a set of paragraphs which are
arranged into rows and columns
• In WordprocessingML, tables are block level
content, and are specified using the table
element
– Analogous to the HTML <table> element
4. Tables
• A WordprocessingML table consists of four
components:
– Table properties
– Table grid
– Table Rows
• Table cells
7. Table Properties
• Table style
– Conditional
formatting flags
– Rows per row band
– Columns per column
band
• RTL vs. LTR
• Alignment
• Sizing
– Preferred Width
– AutoFit vs. fixed
width
– (these two are
important, we'll
come back to them)
• Indentation from
margin
8. Table Properties (cont'd)
• Table Positioning
– Distance from text
(when floating)
– Can overlap with
other tables?
• Borders
– Top, bottom, left,
right
• Cell Margins
• Shading (for spacing
gaps)
• Table property
revisions
9. Table Grid
• Defines a virtual 'grid' used to lay out cells in
the table
• The grid defines a set of edges which are
shared by cells
– If two cells want to share the same number of grid
units, they *must* be the same width
– For example, if R1C1 spans two grid columns, its
right edge *must* match up with R2C2 (assuming
each cell in R2 is one grid unit)
10. Table Grid
• The grid columns themselves do not
determine the size of the table cells
– Determined based on the actual table properties
– They represent the result of the last table AutoFit
11. Table Grid Example
• In this following table, there are four grid
columns:
• The first cell in rows 1 & 3 span two grid
columns, the second is indented by one grid
column
1 3 42
13. Table Rows
• Define the contents of a table row, and are
represented by the tr element
– Analogous to the HTML <tr> element
• Table rows can contain any of the following:
– Table row properties
– Custom markup (Custom XML, structured
document tags)
– Table cells
15. Table Row Properties
• Table-Wide Property
Exceptions
– Table properties that
are overridden for
this row (e.g. cell
spacing, preferred
width)
– Row height
– Cell spacing
• Conditional
formatting
– Header row flag
• HTML <div>
reference
• Row contents cannot
break across pages
16. Table Row Properties
• Grid units
• Before and after
• Preferred width
– Before and after
• Row alignment
• Hidden row
• Row property
revisions
These two properties combined
determine the layout of the row in the
table, as seen with the grid earlier
17. Table Cells
• Define the contents of a table cell, and are
represented by the tc element
– Analogous to the HTML <td> element
• Table cells can contain table cell properties as
well as block level content
– This implies that tables can be nested, etc.
19. Table Cell Properties
• Conditional
formatting
properties
• Vertical merge
• Borders
– Top, left, right,
bottom
• Cell shading
• Text wrapping
• Cell margins
• Text flow
– RTL vs. KTR
– Top to bottom vs.
bottom to top
• Vertical alignment
• Text fit
20. Table Cell Properties (cont'd)
• Cell preferred width
• Grid span
• Table cell property
revisions
These two properties will
determine the size of the
table cell
21. Table Layout
• Table layout is a compilation of table
properties:
– The table grid
– Table-level properties (e.g. preferred width)
– Row-level properties (e.g. grid before/after)
– Cell-level properties (e.g. preferred width)
22. Table Layout - Widths
• It is important to note that every width in a
table is a preferred width because:
– The table must satisfy the grid at all times
– Table properties in the document can be
conflicting
23. Table Layout - Widths
Both of these cells
span the same grid
unit, but they have
different preferred
widths!
The consumer has
to override one of the
'preferences'
24. Table Layout
• Therefore, we assemble these properties into
the table based on the type of table:
– Fixed Width
• This table does not resize based on its content
– AutoFit
• Defined from the existing W3C table AutoFit algorithm,
this table dynamically resizes itself depending on its
contents
25. Table Layout Example
• Let's construct a table in Word using each
logic:
• Table has four grid columns, one cell spanning
two grid columns, and two rows with grid
columns before or after
26. Fixed Width Table Layout
1.Create the table grid based on the grid data
• If table grid data is omitted, infer it as the table is
constructed
27. Fixed Width Table Layout
2.Get table's preferred width from tblW table
property
• This defines the total table width
• If it is of type "auto", then the table has no
preferred width and is determined based on the
row/cell data
No preferred
table width
28. Fixed Width Table Layout
3.Read table row:
• Start by skipping specified # of grid units
• Total width of skipped grid columns is then set
based on the row data
In this case, row
one has no grid
units before, so we
do nothing for this
row.
29. Fixed Width Table Layout
4.Read each table cell:
• Place cell on the grid
• Spans # of grid columns specified
• Total width of those columns is then set based on
cell's preferred width
2214 twips
30. Fixed Width Table Layout
• Here’s the table grid after row one is
complete:
• In row two, the row specifies that it has two
grid units after, so we end it two grid units
early:
2214 twips 2214 twips 2214 twips 2214 twips
2214 twips 2214 twips 2214 twips 2214 twips
2214 twips 2214 twips
31. Fixed Width Table Layout
• In row three, we start with a gridBefore value
of two, so we move in two grid units to start
• The only cell in this row also specifies a
gridSpan of two, so it spans the next two grid
units
• Here's the resulting table:
2214 twips 2214 twips 2214 twips 2214 twips
2214 twips 2214 twips 4428 twips
4428 twips 4428 twips
32. Fixed Width Tables – Handling
Inconsistency
• That table was well-behaved (all the
measurements matched)
• If it wasn't:
– Rule 1: The table grid is gospel; two cells which
snap to the same grid units must have the same
width
33. Fixed Width Tables – Handling
Inconsistency
• If it wasn't (cont'd):
– If the total preferred with for all grid columns
exceeds the preferred table width, each grid
column is reduced in width to fit the preferred
table width
– Rule 2: Table width preference has precedence
over cell width preferences
34. Fixed Width Tables – Handling
Inconsistency
• If it wasn't (cont'd):
– If the content overflows the grid, the grid is
dynamically increased
– Rule 3: The table grid can be redefined to match
the grid size implied by the content
35. Fixed Width Tables – Handling
Inconsistency
• If it wasn't (cont'd):
– If two grid columns sizes disagree, force the grid
column width to the maximum preferred width
requested, then reduce the table based on Rule 1
– Rule 4: If two grid columns sizes disagree, the grid
column size is the maximum of the two before
applying Rule 1
36. AutoFit Table Layout
• The other style of table is an AutoFit table,
which dynamically resizes to fit its contents
• The algorithm is based on the published W3C
spec for table AutoFit, with provisions for
gridBefore/gridAfter
37. AutoFit Table Layout
1.Create the table grid based on the grid data
• If table grid data is omitted, infer it as the table is
constructed
38. AutoFit Table Layout
2.Get table's preferred width from tblW table
property
• This defines the total table width
• If it is of type "auto", then the table has no
preferred width and is determined based on the
row/cell data
No preferred
table width
39. AutoFit Table Layout
3.Read table row:
• Start by skipping specified # of grid units
• Total width of skipped grid columns is then set
based on the row data
In this case, row
one has no grid
units before, so we
do nothing for this
row.
40. AutoFit Table Layout
4.Read each table cell:
• Place cell on the grid
• Spans # of grid columns specified
• Total width of those columns is then set based on
cell's preferred width
2214 twips
41. AutoFit Table Layout
• Here’s the table grid after row one is
complete:
• In row two, the row specifies that it has two
grid units after, so we end it two grid units
early:
2214 twips 2214 twips 2214 twips 2214 twips
2214 twips 2214 twips 2214 twips 2214 twips
2214 twips 2214 twips
42. AutoFit Table Layout
• In row three, we start with a gridBefore value
of two, so we move in two grid units to start
• The only cell in this row also specifies a
gridSpan of two, so it spans the next two grid
units
• Here's the resulting table:
2214 twips 2214 twips 2214 twips 2214 twips
2214 twips 2214 twips 4428 twips
4428 twips 4428 twips
43. AutoFit Table Layout
• So far, this is identical to the fixed width table
case
• All of the inconsistency rules apply at this
stage as well
• The difference comes now that the table
structure has been established, and we’re
going to populate the contents of the table…
44. AutoFit Table Layout
5.Place the text in each table cell:
• Based on the presence (or lack) of breaking
characters, the text width may exceed the cell's
preferred width
• If it does, preferences are overridden
45. AutoFit Table Layout
• Preferences are overridden as follows:
• First, override the preferred cell width by making
other grid columns proportionally smaller until
each is at its minimum width
• Next, override the preferred table width until the
table reaches the page width
• Finally, force a line break in the cell contents as
needed
46. Table Layout Summary
• Summary of rules:
– Rule 1: The table grid is gospel; two cells which
snap to the same grid units must have the same
width
– Rule 2: Table width preference has precedence
over cell width preferences
• Rule 2a: In AutoFit table, the text width has preference
over both
47. Table Layout Summary
• Summary of rules (cont'd):
– Rule 3: The table grid can be redefined to match
the grid size implied by the content
– Rule 4: If two grid columns sizes disagree, the grid
column size is the maximum of the two before
applying Rule 1
48. Vertical Cell Merges
• So far, we've looked at tables as if they have
strict definitions of rows
• Not true:
Vertically merged cell
49. Vertical Cell Merges
• Cells are merged vertically using the vmerge
element
– A vmerge element of type "restart" begins or
restarts a vertically merged region
– A vmerge element of type "continue" continues a
vertical merge
• All cells in the same grid column after a restart
are merged vertically
50. Vertical Cell Merges
• Only the contents of the first cell are kept
– The other cells don't exist after the merge
51. Disclaimer
This presentation is for informational purposes only, and should
not be relied upon as a substitute or replacement for Microsoft
formal file format documentation, which is available at the
following website: https://msdn.microsoft.com/en-
us/library/cc313118(v=office.12).aspx. Any views or opinions
presented in this material are solely those of the author and do
not necessarily represent those of Microsoft. Microsoft
disclaims all liability for mistakes or inaccuracies in this
presentation.