Use Word's TOC field to fine-tune your table of contents
Adding a table of contents (TOC) to a long Word document is easy, thanks to the user interface options in the Ribbon versions. But there’s more to the feature than you might realize. The TOC is actually built from a field you can manually alter. In fact, doing so is the only way to apply some of the feature’s more advanced options. In this article, I’ll show you two such features: We’ll omit page numbers from individual levels and generate a partial TOC.
I’m using Word 2013 with Windows 7 but you can easily apply these instructions to all of Word’s ribbon versions. You can work with any simple document or download the demonstration .docx file.
This article assumes that you’re familiar with Word’s TOC feature and fields. If you’re not, you might want to read How to insert a table of contents into a Word document before you continue with this article—but doing so isn’t strictly necessary to follow this article.
There are no instructions for Word 2003 in this article. If you’d like to learn more about generating a TOC using Word 2003, please review the following articles at Microsoft.com:
About Word’s TOC field
In a nutshell, fields are dynamic placeholders. More specifically, a field is a set of instructions that perform an action automatically. You probably use them often without realizing it. For instance, when you insert a page number into a document’s header, you’re inserting a field. As Word evolves and offers more feature via the interface, fields are less visible, but you’re still using them.
Word’s Ribbon-based interface does such a good job of walking users through the process of generating a TOC, most don’t realize that the resulting TOC is actually a field. And more options are available if you know how to modify the underlying field. You may never need these features, but it’s good to know they’re available just in case.
Before we continue with the actual TOC technique, let’s examine a TOC field. Figure A shows a typical TOC. On the surface; it appears to be ordinary text—but there’s more than meets the eye. To expose the field that controls the TOC, click inside the TOC and press [Alt]+[F9.] Figure B shows the TOC’s field and switches.
You can’t see the TOC’s underlying field.
Press [Alt]+[F9] to see the TOC field’s switches.
The field tells you everything you need to know. TOC is the identifier, the table of contents field. Everything else is a switch with arguments:
- o “1-3” is the default level argument and tells Word to include Heading 1, Heading 2, and Heading 3 in the TOC.
- h is the hyperlink switch that turns each entry into a hyperlink to the associated section. If you delete this switch, only the page numbers are hyperlinked.
- z hides tab leaders and page numbers in Web Layout view because they’re irrelevant in the web environment.
- t “TOC Summary, 4” adds a style other than the built-in heading styles to the TOC. In this case, the TOC includes a custom style named TOC Summary as the fourth level.
If you know how to interpret the switches, you can quickly discern that this TOC has four levels. The first three use the built-in heading styles and a fourth is based on a custom style to generate hyperlinked entries. The first three switches are defaults; t was added to display annotations for the third-level entries. To learn how to annotate an entry, read Use a custom style to annotate a Word table of contents.
For a complete list of TOC switches, read Field codes: TOC (Table of Contents) field.
Omit page numbers
The annotations shown in Figure A are the result of applying a custom style to the TOC’s fourth level. When annotating a section, you probably won’t want to include the (default) page number and you can’t turn them off using a dialog interface option.
When generating the TOC, you can uncheck the Display Page Numbers option, shown in Figure C to disable all page numbering. Doing so adds the n switch to the field code. For example, if we had done this in our example, the field code would be TOC o “1-3” n h z t “TOC Summary,4” . The resulting TOC would have no page numbers.
Disable page numbering in the TOC.
What you can’t do via the interface is disable page numbering for a specific level — it’s an all-or-nothing setting. Fortunately, you can manually alter the field code to disable page numbering for a specific level by specifying the level in an x-z format where x is the first level and z is the last. To disable page numbering for the annotation level (the fourth level), add 4-4 to the switch, as shown in Figure D.
Manually specify a level to disable page numbering for that level.
After altering the field, press [Alt]+[F9]. Then, right-click and choose Update Field. In the resulting dialog, choose Update Entire Table and click OK to generate the new TOC, shown in Figure E.
Remove page numbers for a specific level.
Add a partial TOC
You might want to include a partial TOC for specific sections. For this, you’ll use the b switch and a bookmark. First, select the section in question. In the example document, we’ll select the entire Quick Themes section:
- Quick Themes: Heading 1
- Theme Gallery: Heading 2
- Quick Styles: Heading 3
To create the bookmark, do the following:
- Select the entire section you want bookmarked. In this case, that’s the three sections mentioned above.
- Click the Insert tab.
- Click Bookmark in the Links group.
- Enter a name, such as TOCsub1 (Figure F).
- Click Add.
Enter a name for your bookmark.
Now, generate the partial TOC as follows:
- Position the cursor where you want to display the TOC.
- Press [Ctrl]+[F9] and Word will insert a pair of code brackets.
- Between the brackets type TOC b TOCsub1 o “1-3” (Figure G).
- With the entire field code selected, press [Alt]+[F9] to display the field code.
- If the TOC isn’t visible, right-click the (seemingly blank) spot and choose Update Field to see the TOC shown in Figure H.
Type this text inside the brackets.
Generate a partial TOC.
TOC codes add flexible solutions
Once you’re beyond basics, you can use field code switches to add more advanced TOC features. There’s almost nothing you can’t accomplish with the right switch and a bit of creative strategy.
Send me your question about Office
I answer readers’ questions when I can, but there’s no guarantee. When contacting me, be as specific as possible. For example, “Please troubleshoot my workbook and fix what’s wrong” probably won’t get a response, but “Can you tell me why this formula isn’t returning the expected results?” might. Please mention the app and version you’re using. Don’t send files unless requested; initial requests for help that arrive with attached files will be deleted unread. I’m not reimbursed by TechRepublic for my time or expertise when helping readers, nor do I ask for a fee from readers I help. You can contact me at [email protected]
Other TOC techniques?
What customization tricks have you accomplished by tweaking Word’s TOC field? How about other fields? Share your tips with fellow TechRepublic members.
View original post here: