You can use built-in options to build a simple table of contents, but quite often, you'll need to change the underlying field code to get the results you want.
Word's table of contents (TOC) feature is powerful and flexible but getting the results you need isn't always possible using its built-in options. Often, you must modify the underlying field code to get certain results. That's what Giovanni ran into. He wants to remove page numbers from an annotation. Fortunately, the solution is simple, if you know how to modify the TOC's underlying field code.
A field code is a set of instructions that you can modify—smart text, of a kind. The results aren't literal text, but the field code displays text. You can customize a field code by adding switches. Often, a switch is the only way to make certain customizations. Switches are just more instructions.
I'm using Office 365 on a Windows 10 64-bit system, but this solution will work in older versions. However, it isn't supported by the browser version, although you can update an existing TOC. You can work with any document or download the demonstration .docx and .doc files.
LEARN MORE: Office 365 Consumer pricing and features
Word offers two ways to insert a TOC:
- Using the Table of Contents option on the References tab offers a gallery with a few pre-defined TOCs, and access to customizing options.
- Using Quick Parts on the Insert tab lets you enter the TOC's underlying field code manually.
Both offer options that allow you to customize all levels of your TOC. However, neither option lets you omit page numbers from a specific level. You can, however, remove all page numbering, which is something you probably won't want to do often.
Use the Reference tab
If you plan ahead, you may know that you want to omit page numbers and create the TOC accordingly--for the most part. For instance, the simple document shown in Figure A needs a TOC. We've already applied Heading 1 to the section text and Heading 4 to the annotation text. (Using built-in styles isn't strictly necessary to create a TOC, but it's the easiest way.) We don't want page numbers displayed for annotations; currently, we have only two levels: Heading 1 and Heading 4.
First, let's use the Reference tab to insert a TOC and see if we can turn off page number:
- Position your cursor within the document where you want the TOC to be.
- Click the References tab.
- In the Table of Contents group, click Table of Contents, and choose Custom Table of Contents from the dropdown. Notice that the Print Preview display (Figure B) doesn't display Heading 4 (the style we used for the annotations). This feature defaults to three levels, Heading 1, Heading 2, and Heading 3.
- To add the annotations to the TOC, click Options. In the resulting dialog, enter 4 in the TOC level control to the right of Heading 4 (Figure C), and click OK. You might consider removing levels 2 and 3 because Heading 2 and Heading 3 are in use, but I recommend that you don't. You might add them later, and when the TOC doesn't update to show those levels, you might not remember why.
- Uncheck the Show page numbers option (Figure D). Before clicking OK, notice that the preview now displays Heading 4.
- Click OK to return to the document. Figure E shows the resulting TOC. All page numbers are gone, but we want to remove the page number only for the annotation level.
Without page numbers, the TOC isn't particularly useful. In fact, it's not obvious that it is a TOC. Before you continue, delete the TOC by right-clicking anywhere inside the TOC to select it. Then, press Delete twice.
Insert a field code
The References tab doesn't allow you to remove page numbering from a specific level. Inserting the TOC field code will have similar results.
To insert the field code manually, do the following:
- Position the cursor where you want the TOC to be.
- Click the Insert tab.
- In the Text group, click Quick Parts and choose Field from the resulting dropdown.
- In the Field Names list, choose TOC. The Table of Contents button will display the same dialog used previously (when you added Heading 4 and unchecked the page numbering option), but don't click the button now.
- Click OK to see the TOC shown in Figure F.
The annotations are included this time because you added Heading 4 in the previous section. You can use both methods to create the TOC with or without page numbers. However, neither method lets you remove page numbers from a specific level--Heading 1 or Heading 4.
Remove page numbers from annotations
For better or worse, the built-in page numbering option is all-or-nothing. However, you can directly alter the field code to disable page numbering for specific levels. If field codes are new to you, don't worry—you'll catch on quickly.
Before we make any changes, let's examine the field code itself. To do so, right-click anywhere inside the TOC and choose Toggle Field Codes. Figure G shows the resulting field code. The default code that we added earlier has little to distinguish itself. (If you insert the TOC using the References tab, the field code will display more information.)
We'll use the \n switch to remove page numbers from the fourth level (the annotations) using the following format:
The switch is \n and the first and last parameters identify the levels. In this case, we'll use \n 4-4 because we're omitting page numbers only from level 4. If you enter 1-4, you'd omit page numbers from levels 1 through 4. You must enter both boundaries--\n 4 won't work.
To modify the field code, insert the cursor between TOC and \ and enter \n 4-4. Add a space character to separate the new switch from the format switch, as shown in Figure H.
To display the results of the code, shown in Figure I. right-click the field code and choose Update field. As you can see, adding the \n switch removes page numbers for level 4—the annotations.
Alter field code for more flexibility
Sometimes the only way to get what you want when customizing a TOC is to alter the TOC's underlying field code. There's almost nothing you can't accomplish with the right switch and some creative planning.
Send me your question about Office
I answer readers' questions when I can, but there's no guarantee. Don't send files unless requested; initial requests for help that arrive with attached files will be deleted unread. You can send screenshots of your data to help clarify your question. 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 that you're using. 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@example.com.
Most likely, you'll want the annotation text to have the same formatting as the rest of the text. To simplify this example, I skipped doing so. To learn how to do this, read Use a custom style to annotate a Word table of contents.
- How to use Excel's fill handle to make quick work of serial dates (TechRepublic)
- How to add vertical lines to a Word document using Office 365 (TechRepublic)
- How to add a drop-down list to an Excel cell (TechRepublic)
- 10 Excel time-savers you might not know about (free PDF) (TechRepublic)
- Cost comparison calculator: G Suite vs. Office 365 (TechRepublic Premium)
- You've been using Excel wrong all along (and that's OK) (ZDNet)
- It takes work to keep your data private online. These apps can help (CNET)
- Get more must-read Microsoft coverage (TechRepublic on Flipboard)
Affiliate disclosure: TechRepublic may earn a commission from the products and services featured on this page.