Customizing your table of contents with switches
Even if you’ve been using Word for a long time and consider yourself adept at using most of its features, you may never have had occasion to generate an automatic table of contents. Many users don’t even realize that there is a way to generate tables of contents automatically; they painstakingly create them by hand, even manually hyperlinking the entries to the headings. This is quite unnecessary!
Although very early versions of Word required the user to insert TC fields as the basis for a table of contents (TOC field), this is usually no longer necessary. As far back as Word 2.0 for Windows, a Table of Contents dialog (accessed via Insert | Index and Tables) allowed users to create a simple table of contents based on Word’s built-in headings, eliminating the need to mark items for inclusion with a TC field. In current versions this dialog is accessed as follows:
Using Word’s built-in heading styles is still the easiest way to create a TOC, but Word’s dialog now also allows you to build the table of contents from specific styles that you designate (built-in or user-defined), from paragraphs assigned specific outline levels (whether defined in the paragraph style or assigned as part of direct paragraph formatting), or by using TC fields. Word MVP Shauna Kelly’s article “How to create a table of contents in Microsoft Word” explains the basics of TOC creation and links to articles with more information. In addition, the Help file in most versions of Word is pretty thorough; in recent versions, the Help index also provides links to online demos (see below).
Although the methods involved may not be immediately obvious (figuring out how the Table of Contents dialog works can require some trial and error, especially if you don’t consult the Help file), creating a table of contents in this way is so easy that many users, especially those unaccustomed to using fields, may be unaware that what they are doing is inserting a TOC field, or that, as is the case with most other fields, the way the TOC field is displayed can be modified by various field switches.
Many of these switches can be added to the field (transparently to the user) by choosing specific options in the Table of Contents dialog. But some of them can be used only by editing the TOC field directly. Those are the ones this article will discuss (switches pertaining to tables of figures and tables of contents built from TC fields are not treated here).
Peeking behind the curtain
To understand how to use these switches, you should first examine the TOC field inserted by default. To see this field, select your table of contents and press Alt+F9 to display the field code. If you have not changed any of the settings in the initial Table of Contents dialog (that is, you chose a table of contents based on Headings 1–3, including page numbers, right-aligned and with period leaders), you will see the following field:
The \o switch with its argument "1-3" tells Word to use Headings 1-3 to build the table of contents. The page number settings are defaults, so no switches are needed to tell Word what to do; switches are needed only when you want to override the defaults.
The \h switch means “hyperlink.” It’s what makes each entire table of contents entry (and not just the page number) into a hyperlink to the associated heading.
The \z switch hides tab leaders and page numbers in Web Layout view; it is used in conjunction with the \h switch because TOCs for Web pages need to have the entries hyperlinked (Web pages don’t have numbered pages).
Omitting page numbers
As stated above, switches are used to change the default settings. For example, if you do not want your table of contents to display page numbers, you can clear this check box in the Table of Contents dialog. When you do that, you will see that the \n switch has been added to the field, so that it looks like this:
But suppose you want to show page numbers for some levels but not for others? In that case you can specify a range of entry levels for which page numbers should be omitted. The example given by Word’s Help (in some versions) is \n 3-4 to omit page numbers from levels 3 and 4. What is not spelled out, and may not be immediately obvious, is that if you want to omit page numbers for a single level, say Heading 1, this must still be expressed as a range, so you would have this:
A partial table of contents
Sometimes you may want to have a table of contents for just part of your document. Perhaps you want to put a table of contents for each chapter at the beginning of that chapter. For this you use the \b switch. Select the portion of the document you want the table of contents to cover and assign a bookmark, such as “Chapter1.” Then insert the \b switch, followed by the bookmark name, in the TOC field, like this:
If your chapter title is the only Heading 1 in the chapter, you probably won’t want it included in the chapter table of contents. In Word’s Table of Contents dialog, using the Options, you can deselect Heading 1. If you do this, you’ll see that the field now says:
That is, the table of contents will use Headings 2 through 9. If you want to include all the heading levels in the chapter (though I hope you don’t have nine!), you can leave it this way. If you have Headings 2 through 4 and want to include only Headings 2 and 3, you can change this to:
You’ll notice that when you do this the table of contents is built using the TOC 2 and TOC 3 styles. If you would prefer to use TOC 1 and TOC 2 styles for your Heading 2 and Heading 3 entries, you can change the outline levels in the Table of Contents options to 1 and 2. You’ll see that your TOC field now says:
If you look at Word’s Help file, you’ll see that the description of the \t switch explains how this works, but you don’t need to know that because you can accomplish it through the Table of Contents dialog (aren’t you glad?). Note that this switch is also added if you select styles other than Word’s built-in heading styles to be included in the table of contents, and that you can have more than one style at a given level; for example, both chapter titles and appendix titles can be assigned outline level 1, and they will be formatted with the TOC 1 style.
A really useless switch
Word’s Help file has this to say about the \p switch:
Unfortunately, as admitted in several Microsoft Knowledge Base articles, this switch does not work as advertised. No matter how many characters you put between the quotation marks, you get just one in the table of contents. Luckily, the Table of Contents dialog allows you to select period, hyphen, underline, or no leaders.
An almost useless switch
The \w switch, according to Word’s Help, “preserves tab entries within table entries.” If you have a tab character in every heading at a certain level, you may find this useful. Without it, the tab character is preserved in the table of contents entry, but it doesn’t act like a tab; that is, it doesn’t advance the text following it to a tab stop; instead, it just inserts space roughly equivalent to three normal spaces or an em space.
With the \w switch, the tab character behaves as expected; if no other tab stop is set, it pushes text to the default right tab stop where the page number would normally be (the page number, if any, winds up on the next line), but you can set a custom tab stop in the TOC style for that level, and the tab character will align the following text there. If the heading doesn’t contain a tab character, though, the page number will end up at the tab stop you set instead of at the right margin. This switch is therefore of dubious usefulness unless you have a heading style that invariably includes a tab.
Finally, a switch that is potentially useful
Sometimes you will have headings so long that they wrap to a new line. Whether these are centered heads or sideheads, most style manuals will advise you to break them short of a complete line. The way to do this is with a line break (Shift+Enter). You may even have more than one line break in a long heading. When this heading is picked up as a table of contents entry, the line breaks are converted to spaces. Often this is quite satisfactory: the fonts used in table of contents entries are often smaller than those used by the headings, and a two-line heading may fit quite comfortably on one line in the table of contents. If not, you can apply a right indent to the TOC style to wrap entry text short of the page numbers. But if you want the table of contents entries to break exactly the same as the headings themselves, you can add the \x switch to the TOC field, and line breaks (Word’s Help calls them “newline characters”) will be preserved. Unlike the \w switch, this has no effect on any entries that do not contain line breaks.
If you’re curious
Word’s Help file describes several other TOC field switches you may want to experiment with if you’re feeling adventurous. Even if you don’t need them today, just knowing they’re there may help you if you eventually do find a need for them.
Finding the appropriate Help topic can be a challenge, however. In Word 2003, the topic “Field codes: Table of Contents (TOC) field” is the one you want. For Word 2007 and above, you can find the Help topic online.
In addition, for more information on formatting and fine-tuning your TOC, see my article on “TOC Tips and Tricks.”
This article copyright © 2001, 2016, 2018 by Suzanne S. Barnhill.