Page 4 of 17PREVNEXT

Table of Contents III: Use fields to create a TOC and create multiple TOCs

TOC field code

In this TOC field, the \o "1-3" switch builds the TOC based on text marked with heading styles Heading 1, Heading 2, and Heading 3. The \h switch turns the TOC entries into hyperlinks.

Say, for example, that you want to exclude page numbers for some levels in your TOC. One option would be to delete the page numbers manually and remember not to update the TOC. But that is hardly a reliable solution; the better way is to use field switches.

Field switches are commands inside the field that determine what the code does. The real power of fields comes into effect with the switches. Switches are added to the end of a field code and within the curly brackets; they always start with a backslash (\). An automatic TOC puts the switches in for you, but you can add, remove, or change the switches later.

A TOC field can have more than one switch. The TOC field in the illustration includes the \o "1-3" switch, which builds the TOC based on text marked with heading styles Heading 1, Heading 2, and Heading 3. The \h switch turns the TOC entries into hyperlinks.

To add a switch, you type a backslash (\) and the switch letter inside the curly brackets. For example, to remove all page numbers in the TOC, use the \n switch, as follows:

{ TOC \o "1-3" \h \n }

While you can also remove all the page numbers by using the Table of Contents dialog box, if you want to remove the page numbers from just levels 2 and 3, you will need to use the \n switch and type the levels, such as:

{ TOC \o "1-3" \h \n "2-3"}

Note     The levels to be excluded with the \n switch must always be represented by a range, so if you want to remove page numbers for just level 3 entries, you would use "3-3" in the switch.

For an explanation of all the switches for TOC fields, click Quick Parts in the Text group on the Insert tab, and then click Field. Select the Index and Tables category and the TOC field name. Then click Field Codes and then Options. The Field Options dialog box lists all the switches with a description of each.

Page 4 of 17PREVNEXT