|
|
|
 |
Customizing your table of contents with switches
|
Article contributed by Suzanne Barnhill
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. In fact, if you started using Word several versions back, you may have avoided making a table of contents because it seemed to require a lot of tedious work. Actually, as far back as Word 2.0, a Table of Contents dialog (accessed via
Insert | Index and Tables just as it is today) 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.
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. All of these options are described pretty clearly in Word's Help file in the article
tables of contents,
creating and other articles linked to it.
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. The Help article
TOC (Table of Contents)
field spells these out.
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:
{ TOC \o "1-3" }
If you have Word 2000, you will see this field instead:
{ TOC \o "1-3" \h \z } The \h switch is Word 2000specific, and 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. If you find this behavior inconvenient or annoying (as many users apparently
do, although the feature was introduced because it was much requested, and most
people want it), you can change it by deleting this switch and updating the
field. Doing that will not affect the page numbers, which will still be hyperlinks.
The \z switch, also Word 2000specific, hides tab leaders and page numbers in Web Layout view.
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.
Omitting page numbers
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:
{ TOC \o "1-3" \n }
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.
For example, says Word's Help,
{ TOC \n 3-4 } omits 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:
{ TOC \o "1-3" \n 1-1 }
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:
{ TOC \b Chapter1 \o "1-3" }
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:
{ TOC \b Chapter1 \o "2-9" }
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:
{ TOC \b Chapter1 \o "2-3" }
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:
{ TOC \t "Heading 2,1,Heading 3,2" }
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: Specifies the characters that separate an entry and its page number. For example, the field
{ TOC \p "---" }
displays a result such as 'Selecting Text---53.' The default is a tab with leader dots. You can use up to five characters, which must be enclosed in quotation
marks. 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. Warning:
Not only is this switch really useless, but you might find that Word sometimes
inserts it for you, ruining the look of your table of contents in the process.
For example, I recently defined my TOC 1 style to be centered; and although the
style had a right-tab in the appropriate position, centering the TOC style had
persuaded Word that the page numbers couldn't be right-aligned. Accordingly it
had very helpfully inserted the switch: \p " " As a
result, all the page numbers were jammed up against the titles, just one space
separating them. Removing the switch fixed the problem.
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 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 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.
|