A section is a stretch of a document with its own page setup, headers and footers. Its
properties are in a w:sectPr. Every section but the last ends with a paragraph
that has w:sectPr in its w:pPr; the properties of the last section
are the last child of w:body.
Section properties: w:sectPr
<w:sectPr>
<w:headerReference w:type="default" r:id="rId7"/>
<w:footerReference w:type="default" r:id="rId8"/>
<w:pgSz w:w="11906" w:h="16838"/>
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440"
w:header="708" w:footer="708" w:gutter="0"/>
<w:cols w:space="708"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
| Element | Meaning |
|---|---|
w:headerReference, w:footerReference | A header or footer part, by relationship ID, with w:type default, first or even. |
w:type | How the section starts: nextPage (the default), continuous, evenPage, oddPage or nextColumn. |
w:pgSz | Page size in twips: w:w, w:h, and w:orient for landscape. |
w:pgMar | Margins, and the distance of the header and footer from the page edge. |
w:cols | Newspaper columns: w:num, w:space, or one w:col each. |
w:pgNumType | Page numbering: format and starting number. |
w:titlePg | The first page of the section has its own header and footer (the first type). |
w:footnotePr, w:endnotePr | Note properties for the section. |
w:lnNumType | Line numbering. |
w:docGrid | The document grid. |
w:sectPrChange | The previous properties, under tracked changes. |
Section properties in detail
Compared with ECMA-376 Part 1 (17.6.4, 17.6.11, 17.6.12, 17.6.13, 17.6.18):
- The other children of
w:sectPr:w:bidi(17.6.1, right-to-left section layout),w:formProt(17.6.6, only form fields editable),w:paperSrc(17.6.9),w:pgBorders(17.6.10; the viewer draws it, andw:displayfirstPagelimits it to the first page of the section whilenotFirstPagedraws it on every other page, which is Word’s reading, MS-OI29500 2.1.549),w:printerSettings(17.6.14, a relationship to a printer settings part),w:rtlGutter(17.6.16, gutter on the right),w:textDirection(17.6.20) andw:vAlign(17.6.23, vertical alignment of the text on the page). w:pgSz:w:wandw:hare the page size in twips and are always as drawn;w:orient(portrait if omitted) says the paper is turned for printing, so the width and height of the paper are the reverse ofw:wandw:h.w:codeis only a producer's label for the paper size and never decides the size.w:pgMar:w:topandw:bottomare signed. When non-negative, the text starts at the greater of the margin and the extent of the header (or footer); when negative, the text is measured from the page edge whatever the header holds and may overlap it.w:headerandw:footerare the distances from the page edge to the header and footer.w:gutteris extra space added on top of the margin for binding.w:cols: withw:equalWidthtrue the childw:colelements are ignored: the width between the margins is divided byw:num, andw:spaceis left after each column. Withw:equalWidthfalse,w:numandw:spaceonw:colsare ignored and eachw:colgives its ownw:w(width) andw:space(space after).w:sepdraws a vertical line in the centre of the space between columns.w:pgNumType:w:startis the number of the first page of the section; when omitted, numbering continues from the highest number of the previous section.w:fmtis an ST_NumberFormat.w:chapStyleis the one-based index of the heading style whose numbering becomes the chapter part of the page number, andw:chapSepthe separator between chapter and page; if no such numbered heading exists, both are left out.
Header and footer parts
Each header is a part with the root w:hdr, and each footer one with the root
w:ftr, usually named word/header1.xml,
word/footer1.xml and so on. The root holds block-level content, as the body
does. It can use its own relationships for pictures and links.
<w:hdr xmlns:w="…">
<w:p>
<w:pPr><w:pStyle w:val="Header"/></w:pPr>
<w:r><w:t>Annual report</w:t></w:r>
</w:p>
</w:hdr>
Which header is used
In each section:
- The
defaultheader applies to ordinary pages. - With
w:titlePg, the first page uses thefirstheader. - With
w:evenAndOddHeadersinword/settings.xml, even-numbered pages use theevenheader and odd pages thedefaultone.
A section with no reference of a type continues the header of that type from the section before. The rules in ECMA-376 Part 1, 17.10.5 (headerReference) and 17.10.6 (titlePg) are exact about what happens when a type is missing:
- First page: with
w:titlePgand nofirstreference, the first-page header is inherited from the previous section, or is a new blank header in the first section; no other type takes its place. Withoutw:titlePg, afirstreference is ignored and thedefault(odd) header is used. - Even pages: with
w:evenAndOddHeadersand noevenreference, the even header is inherited, or blank in the first section. Withoutw:evenAndOddHeaders, anevenreference is not shown and thedefaultheader is used. - Default (odd): with no
defaultreference it is inherited, or blank in the first section. w:titlePgset to false (or absent): the first page of the section uses the section's starting page number (w:startonw:pgNumType) to decide whether it takes the even or the odd header.
Rules for a valid file (17.10.5): the relationship of w:headerReference must be of the header type and Internal; a section with two references of the same w:type (for headers, or for footers) is non-conformant. w:type is an ST_HdrFtr value (17.18.36). The same applies to w:footerReference (17.10.2).