Adjusting Location of a Heading Code in a TOC

Written by Allen Wyatt (last updated December 13, 2025)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365


Lindsay has a lengthy document (130 pages) where each page has a heading that appears in the TOC. He would like to insert a three-character code in each heading that will appear in the TOC immediately to the left of the right-justified page number. He's not been able to achieve this and would live to find a solution.

The way to accomplish this task depends on exactly where you want the three-character code to appear. It is clear that the code should appear in the TOC, and where it should appear in the TOC (just to the left of the page number), but it is unclear whether the code should also be visible in the headings. So, I'm going to look at both scenarios.

There is one thing you should realize as you work through this tip—I'm assuming you already know how to do basic TOC functions, such as inserting a TOC and updating existing TOCs.

Code Appears in Both Headings and TOC Entries

The standard way of creating a TOC is based on heading styles within a document. When you insert the TOC, Word grabs all the paragraphs formatted with the first three heading styles—Heading 1, Heading 2, and Heading 3—and places them in the TOC. These paragraphs are, in turn, formatted using the first three TOC styles—TOC 1, TOC 2, and TOC 3.

Because the heading in the TOC is formatted with a different style than was used for the actual heading, you can modify the appropriate styles to control how the heading looks in each place.

For instance, let's say that this is your actual heading in the document:

Important Information ABC

Format this heading using the Heading 1 style and make sure that there is a tab character between "Information" and the three-character code ("ABC").

Now, modify the TOC 1 style to include two tab stops. The first should be a left-justified tab stop indicating where you want the three-character code to appear. The second should a right-justified tab stop indicating where you want the page number to appear.

Now, generate your TOC, and the code and page number should be positioned for each TOC element based on the tab stops you set. If you had previously inserted the TOC before you made changes in the TOC 1 style, you'll need to update the TOC. (Make sure you update the entire table, not just the page numbers.)

If the code and page number still don't align as you specified with your tab stops, then you need to make a change to the field used to generate the TOC. Position the insertion point within the TOC and then press Alt+F9. You should see the TOC replaced with the field code used to generate the TOC. It will look very similar to the following:

{ TOC \o "1-3" \h \z \u }

Change the code to add the \w switch, in this manner:

{ TOC \o "1-3" \h \z \u \w }

With the insertion point still within the field code, again press Alt+F9. The TOC should again appear, but the tabbing should now be correct. This is because the \w switch instructs Word to not delete any tab characters from the headings it places in the TOC.

Speaking of the headings, if you look back at them, you may notice that the tab character between the title ("Important Important") and the three-character code ("ABC") means that the horizontal position of the code within the heading may seem strange. That's because the tab means that the following text jumps to the position of the next tab stop. If the Heading 1 style doesn't have any tab stops specified, then the default tab-stop spacing (1/2 inch) is used. You can, of course, modify the tab stops within the Heading 1 style to minimize the horizontal displacement of the code.

Code Appears in TOC Entries, but Not Headings

Things may seem trickier if you don't want the three-character code to appear in the heading. However, it is actually a simple step from the concepts discussed in the previous section.

Make sure you set up everything as already described, but also create a new character style. (Not a paragraph style, mind you, but a character style.) Name this style something meaningful, such as "Hide Code." The only thing that is necessary within the style definition is to set the font color to white.

Next, go to each heading that includes a three-character code, select the code, and apply the Hide Code style to that text. The code will seem to disappear from the heading, but it will remain in the TOC, even if you update it. This is because character formatting, including formatting applied by a style, is ignored in when pulling headings into the TOC.

You might wonder why you cannot define the Hide Code style to be hidden text, rather than using a white font color. This is because, in testing, it seems that any hidden text is not transferred from the heading to the TOC entry; it is ignored by Word entirely.

An Important Caveat

There is an important caveat to note in these instructions, and you may have already recognized it. The horizontal ordering of elements within headings cannot be different from what you want in your TOC. In other words, you cannot order items as "code, title" in the heading and have it appear in the order "title, code, page number" in the TOC.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (11163) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Extracting Targeted Records from a List

If you have a bunch of data in an Excel worksheet, you may need to work with just a subset of that data. One way to do ...

Discover More

Restoring Items in the Recycle Bin

Placing something in the Recycle Bin does not mean it is gone forever. After placing something there, you may change your ...

Discover More

Using the Magnifier

With high-resolution screens it can be a stretch, at times, to see some small detail on the Windows desktop. Fortunately, ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 365 applications with VBA programming. Written in clear terms and understandable language, the book includes systematic tutorials and contains both intermediate and advanced content for experienced VB developers. Designed to be comprehensive, the book addresses not just one Office application, but the entire Office suite. Check out Mastering VBA for Microsoft Office 365 today!

More WordTips (ribbon)

Mixed Page Number Formats in a TOC

When you create a Table of Contents for a document that contains multiple sections, the page numbers in that TOC should ...

Discover More

Problems with TOC Styles

If you generate a table of contents for your document, there may be some unexpected surprises in the way the TOC appears. ...

Discover More

Customized Tables of Contents

Generating a table of contents is easy in Word. Changing how that table of contents looks is also easy, provided you ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven more than 1?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.