Office Q&A: How to remove page numbers from a table of contents in a Word document

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

TOC basics

Word offers two ways to insert a TOC:

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.

Figure A

First, let's use the Reference tab to insert a TOC and see if we can turn off page number:

Figure B

Figure C

Figure D

Figure E

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:

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.)

Figure G

We'll use the \n switch to remove page numbers from the fourth level (the annotations) using the following format:

\n first-last

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.

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.

Figure I

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 protected]

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.

Also see

Affiliate disclosure: TechRepublic may earn a commission from the products and services featured on this page.