3 wordprocessing ml subject - tables
TRANSCRIPT
Components of WordprocessingML• Main Document• Paragraphs & Rich Formatting
– Runs– Run Content
• Tables• Custom Markup• Sections• Styles
– Paragraph– Character– Numbering– Table– Document Defaults
• Fonts• Numbering• Headers/Footers• Footnotes/Endnotes• Glossary Document• Annotations
– Comments– Revisions– Bookmarks
• Mail Merge• Document Settings
– Web Settings– Compatibility Settings
• Fields & Hyperlinks• Odds & Ends (Textboxes, Subdocuments, Extensibility)
Ecma/TC45/2006/026 (Rev.)
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
Tables
• A WordprocessingML table consists of four components:– Table properties– Table grid– Table Rows
• Table cells
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
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
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)
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
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
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
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
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
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.
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
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
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)
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
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'
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
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
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
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
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 dataIn this case, row one has no grid units before, so we do nothing for this row.
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
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 twips2214 twips 2214 twips
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 twips2214 twips 2214 twips 4428 twips4428 twips 4428 twips
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
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
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
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
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
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
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
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 dataIn this case, row one has no grid units before, so we do nothing for this row.
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
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 twips2214 twips 2214 twips
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 twips2214 twips 2214 twips 4428 twips4428 twips 4428 twips
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…
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
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
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
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
Vertical Cell Merges
• So far, we've looked at tables as if they have strict definitions of rows
• Not true:
Vertically merged cell
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
Vertical Cell Merges
• Only the contents of the first cell are kept– The other cells don't exist after the merge
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.