is now part of CreativePro.com!

Formatting Headings for Inclusion in a Table of Contents

37

So here’s a perennial problem: You make a long document, like a book, then build a table of contents (Layout > Table of Contents)… and the headings show up in the TOC with extra formatting and characters! Specifically, much of the local formatting or character styles you applied to a heading in the document gets pulled into the TOC, even when you wish it didn’t. And, worse, if you inserted any forced line breaks (Shift-Return/Enter) in the heading — usually in order to make it look better as it breaks across two or more lines — also come along for the ride!

For example, here’s a problematic TOC:

The first chapter head has a shift-return in it, so it breaks across two lines — we only want it on one line in the TOC. The third, fourth, and fifth lines have some underlining in it, picked up from local formatting in the document.

Unfortunately, these are the facts of life. There’s no way to make a TOC and automatically strip out the stuff you don’t want. But you can remove the undesirable dross relatively quickly, or even set up the headings in a way that they won’t require so much clean-up later.

Strip the Formatting

Any local character formatting applied to a portion of a paragraph gets included in the TOC. If you select the whole paragraph and apply the local formatting (like changing color or size), it’s ignored in the TOC. That’s why in lines 3 and 4 of the example above, the formatting — color or underlining — appears.

Character styles, however, always get sucked into the TOC, whether you apply them to a letter or the whole paragraph. That’s why the text in the fifth line is all messed up. Note that the formatting even extends out to the page number!

One of the easiest ways to remove the formatting after you create the TOC is to select all the text in the story (the TOC) and click the Clear Overrides button at the bottom of the Paragraph Styles panel. That removes any local formatting. Now, to remove the character styles, click None in the Character Styles panel.

Of course that removes all the formatting! If you need to remove some formatting but keep other formatting, I would suggest checking out the “Type > Remove Local Formatting” feature in the Blatner Tools plug-in suite.

Remove Soft Returns

If you have used soft returns (Shift-return/enter) to force a line of text to break from one line to the next, you’ll probably want to remove those in the TOC. The reason they show up is that they are real characters, albeit invisible ones (along with tabs, column brakes, spaces, and so on).

If they’re already in your TOC, you can strip them out using Edit > Find/Change. In the Find What field, type ^n (caret-n). Leave the Change To field blank. Set the Search pop-up menu to Story (so it just applies to the table of contents), and click Change All.

However, even better advice: Avoid using the soft returns in the headings to begin with. Instead, use paragraph or character formatting to manage the line breaks. For example, you could try using Balanced Ragged Lines to break the heading better. Or adjust the left and right paragraph margins. Or use No Break or some other local formatting that doesn’t involve adding actual characters.

Using formatting to adjust line breaks is better because then you won’t have to take this extra find/change step. And if you later export the text as XML or RTF or HTML or whatever, you don’t need to worry about those extra characters, too!

It’d be nice if there were a way to make a perfectly formed table of contents every time. But in my experience, TOCs almost always require fiddling, fixing, and finagleing. That’s why it’s best to create them as a last step… the fewer times you need to fff them, the better.

David Blatner is the co-founder of the Creative Publishing Network, InDesign Magazine, CreativePro Magazine, and the author or co-author of 15 books, including Real World InDesign. His InDesign videos at LinkedIn Learning (Lynda.com) are among the most watched InDesign training in the world.
You can find more about David at 63p.com

Follow on LinkedIn here
  • Zalman says:

    Thanks for posting this! This was something I was just struggling with.
    Your workarounds are great, but given ID?s limitations in this it?s still a clumsy way to manage a TOC as a project evolves.
    It seems to be just a development oversight, since it makes no real sense to pull formatting over if you?re applying local formatting to the TOC via the style menu ID itself offers in the TOC dialog.

    I wish there?d be a checkbox for the following two options (hello Adobe ID-CS5 team?):

    1. TOC Update “Update page numbers only.”
    2. TOC Build: ?Ignore Local Formatting.”

    Until then, how are you all handling your TOC issues?

    Thanks again!

  • Phil Frank says:

    One of the things I find most troublesome are the heading titles that are long enough to run right into the page number but not long enough to wrap. So they have to be wrapped manually. Every time the TOC is regenerated. Which is not a big deal with a one- or two-page TOC, but a bigger deal in a TOC that functions almost as an outline for a really large and complex book. What I’d like to see is a right indent setting that ignores the tabbed/right-indent tabbed page number.

    • I’ve got a similar problem. Whenever a chapter head wraps into two lines after a particular character, the corresponding Toc entry, whatever style options are applied, will wrap just after the same character and push the second line to the next page, leaving a huge space.

      • @Philippe: My guess is that the chapter name on your document page has a Shift-Return (also called a soft return) inserted there. It’s an invisible character (see Type > Show Invisibles). You may need to manually remove that in the TOC to make it work.

      • Philippe Ramirez says:

        Thanks David, but there is no soft return, neither in the source paragraph nor in the corresponding TOC entry.

      • How can I upload a sample of my TOC so that you see the kind of pb I have?

      • Sorry, we don’t allow uploads. I would suggest asking your question on the forum (click Forums at top). You can share a link to your file at dropbox or some other sharing service there.

      • Philippe Ramirez says:

        Ok, no pb. I’ll do that. Thanks David.
        Philippe

    • Alastair Leith says:

      Yes I was just thinking the same thing about right margin that ignores the tab outside it for the page number to go to. REALLY Annoying Adobe. They do so little to improve ID really each version. Still no Quark like shortcuts for the Spelling panel buttons, I mean you can’t even set them in Keyboard Shortcuts for some unknown reason.

  • Mike Rankin says:

    David-

    You make a great point that’s worth underscoring.

    I think we’re at the point now where you should expect any content will be published across media (and to various devices) at some time. So don’t make your content do the job of formatting. Leave the formatting to the layout. Resize the text frame, change the style, etc. But avoid stuff like those soft returns.

    I know it isn’t always possible to keep content 100% pure, but it will pay off if you can.

  • Martin says:


    This would be very nice!

  • Martin says:

    My cite was eaten…
    I like Zalmans idea:
    1. TOC Update ?Update page numbers only.?
    2. TOC Build: ?Ignore Local Formatting.?

  • Eugene Tyson says:

    If you use a Nested Style in your body text for extra formatting, rather than applying a character style directly.

    Then if you map the style when generating the TOC then you don’t get any extra formatting in the TOC list.

    I know it’s a bit of extra setting up, but generally you’ll only have to do this for headings, and how many different heading styles will you have? I know it won’t work for every layout, but it’s an option at least.

    And also, generally you want the TOC to have a different formatting than the headings, or even if you want the same heading style, I still tend to make TOC Styles like:

    TOC Level 1
    TOC Level 2
    etc.

    That way I can bring in the Headings I want into the TOC dialog box and then assign a Paragraph Style to each one.

    When you generate the TOC you just have to clear the overrides, if you’ve used local formatting. If you’ve used a character style you will have to select the text in the TOC and hold down Alt Shift or Option Shift when clicking the style, to remove the character style (or you may just want to select all the text and change the the Character Style to none).

    But there are cases when I do want “italic” and “bold” to appear in the TOC too. And other cases I wouldn’t want it to appear. So where do you draw the line?

    • fede says:

      i love you man, nested style, i came from the future to learn this, greetings to all 2010ers here. now i go back to 2023. goodbye

  • Ann_Camilla says:

    For Phil Frank: about those long heading titles that don’t wrap. If you set up the ToC paragraph style with:
    1. A right indent of, say, 20mm
    2. A last line indent of -20mm

    and then when you set up the ToC style with the above paragraph style, set the number (page number) with a tab before it — but this is the important bit — the tab MUST (for some reason that escapes me) be a right indent tab (^y).

    Anyway, hope it works for you as it does for me.

  • Phil Frank says:

    Ann,

    Thanks for this. Now that you mention it, I do seem to recall something like this. I’ll definitely check this out.

  • lateregistrant says:

    Is there an automated or interactive way through the TOC feature to show for sections Pages XX-XX instead of just the sole page number. For example based off the image you’ve provided, could it show “Finding A Home Away from Home (3-5)”. Thanks.

  • @lateregistrant: Sorry, I haven’t seen anything like that. Cool idea, though. I guess you could do it with the indexmatic script found elsewhere on this site…. in other words make an index that looks like a TOC.

  • @David Blatner – Thank you, I’ve spent hours trying to figure this out and since this site has been so helpful with teaching me other techniques I figured it was a shot in the dark. I may try the indexmatic script, I was just trying to make the TOC as dynamic as possible as there are over 60 pages and don’t want to have to manually create indexes for everything. I may just have to simplify the TOC.

    Thank you again!

  • Eugene Tyson says:

    David, isn’t there a way to do this with Cross References?

  • faizal says:

    I have a small issue(Big?)with Indesign
    I have two difrent paragaph styles it should appear in a same line on TOC .
    for example .
    I have a heading with ‘style 1′
    and refrence number with’ style 2′ ,when we are creatingTOC both styles should be in same line.
    is it possible?
    I strongly beleive that some one can help me easily.
    Thanks and
    sorry for bad english

  • Bunny says:

    Do you know of any way to mark specific instances of headings so that they are excluded from the table of contents? I could assign a different stylesheet for the instances we want excluded and not include that style in the ToC stylesheet, but since they otherwise are identical to the ones we do want included, and are treated in every other way like those headings, I’d like to be able to assign them the same style but somehow denote “this instance should not be included in the ToC.” Any ideas?

  • Jongware says:

    Bunny: create a new heading style based on your regular style. InDesign distinguishes styles for the TOC by name, so it won’t be included that way. And if you change the original style, the based-on style will change as well.
    You have to remember to change the original, not the derived one.

  • Bethany says:

    I have a document where the headers are preceded AND followed by a bullet character. Because the bullet is at the beginning and the end, I don’t set it up as “Bullets and Numbering” b/c that would only give me one bullet at the beginning. Unfortunately you cannot check a box to to apply another bullet after the text. To complicate matters, this bullet is formatted differently than the text it encloses, so I have a character style applied to the bullets.

    When generating my TOC, it pulls in the bullets and retains their formatting, and applies this formatting to all the text following the bullets (i.e. my tab leaders and page numbers). Fixing the formatting in CS5 was a snap…I just applied a character style to my tab leaders and to the page number. But I still need to manually remove those darn bullets! Is there a way to get the TOC to ignore certain characters? Alternatively, is there a way to apply a beginning and ending bullet to a paragraph style so that they don’t get pulled in when you generate a TOC?

    Thanks!

  • Funkwarrior says:

    I resolve my issue with soft returns on TOC using Non breaking space (Type > Insert White Space >Non Breaking Space)

    Everything is fine now!

  • Janis says:

    Yes, in Indesign are messed up Character and Paragraph styles. And you can not apply all formatting with one click as it was. And you can not give instructions to TOC to have different character style than it is…
    maybe some plugin is able to reformat TOC to character style you need after update?

  • gaz says:

    I have two headers on the same page. i have a three sub headers after header 1. i have two sub headers after header 2.

    when i run TOC, it shows as
    Header 1… page 4
    Header 2… page 4
    Sub header 1.. page 4 (this should be after Header 1)
    Sub header 2.. page 4 (this should be after Header 1)
    Sub header 3.. page 4 (this should be after Header 1)
    Sub header 1.. page 4 (this should be after Header 2)
    Sub header 2.. page 4(this should be after Header 2)

    How can i make subheader 1, 2 3 appear after Header 1 and then hvae Header 2, then their relevant subheaders.
    thanks
    gaz

  • empire4vr says:

    I am have an issue that I can’t seem to find an answer to anywhere. When I insert a ToC it pulls all of the Heading 1’s and 2’s just like I want, but they retain the Heading 1 & 2 formatting from the document no matter what I set them to be in the ToC creation dialog box. I can change them manually after the fact, but every time I Update the ToC they change back. I just want the ToC listing to be in the “Body Text” style I built, not the Heading styles… Anyone have any idea why it’s doing that?

    Thank you!

  • @empire4vr: Possible that a character style is being applied to the text? Place the cursor in the text and see what it says in the Character Styles panel. Also, check to see if there is a + symbol next to the style name in the Paragraph Styles panel.

  • Mislyn says:

    Your website is always so useful. I’ve learned a lot from you. Thanks.

    Here is my problem:

    In my TOC I have a 2-line subhead. Everything is fine except that the 2-line subhead has the same leading as the
    single line subheads and headings in the TOC.

    I want the 2-line subhead to have a different leading so that it can be easier to see that those 2 lines of text belong together.

    So the rest of the TOC has 18pt leading, but I want the 2-line subhead to have, say, 16pt leading. How do I achieve that?

    Thanks

  • Lenny says:

    I have a TOC formatting problem based on paragraph styles. I’m formatting paragraph styles on legal documents like this:

    (paragraph style 1) Article 1.00 ARTICLE HEADING

    (paragraph style 2) 1.01 ARTICLE SUB HEADING. Article Sub Heading paragraph text illustrating legal provision MUST immediately follow in same paragraph.
    1.02 (and so on . . .)

    When creating TOC I cannot separate the style of the Heading from the style of the paragraph because they are in the same paragraph. So TOC format picks up the body text immediately following the Article Sub Heading. I only want the sub heading text, not the following body text, in my TOC.

    I want my TOC to look like this:

    ARTICLE 1.00 ARTICLE HEADING
    1.01 Sub Heading (no further paragraph text)
    1.02 Sub Heading (no further paragraph text, and so on . . .)

    Is there a way to separate the paragraph styles within the same paragraph? Or to eliminate text after number and heading in the TOC options?

    Thank you,
    Lenny

  • Wilhelm says:

    I’ve been fighting a character style on my headings for over an hour now. Adobe should take a hint from CSS and allow !important (ish) function for the TOC styles. It’s a bit of a nightmare now, specially if you want some fancy same-line subtitles in your document.

    C’est la vie, I guess

    (And thanks for the tips, David!)

  • David Creamer says:

    Sometimes, headings need to be different from what the TOC states, or the TOC needs a subhead that is not part of the actual layout. For these situations, I create a text box in the margins, add the text, apply a special style (to make the text stand out more on screen), and make the text box non-printing. The text still picks up in the TOC.

  • Michael says:

    Thank you for all the tips so far!

    I’ve run into a Word 2013 problem that I can’t figure out…. maybe you have some ideas?
    I am using the TOC format to create a list of files we keep in an 8 drawer confidential file cabinet, and I’ve modified several styles so that the layout is optimal.
    My problem seems to be with the first heading, used to identify each drawer (Drawer 1,2,3, etc.). So that each drawer appears on a separate page, I have added a page-break with this style (selected through Modify Style->Format->Paragraph->Line and Page Breaks).
    Everything looks great on the screen, but in Print Preview and after printing, the page-break only works for the first drawer.
    I’m completely dumbfounded and can’t figure out why this isn’t working. Any ideas?
    Thanks!

  • Farhoudi says:

    Hello everyone,
    Thank you for all the tips;

    I want to create a TOC with different colors for different chapters’ title. Is it possible and how can I do that. Here is an image from a TOC which shows what I want to do:
    https://www.dropbox.com/s/o2s30h2gg5eywf6/TOC.jpg?dl=0

    Thank you in advance!

  • Terry Ofner says:

    I found a workaround (of sorts) for character styles in heads carrying into the table of contents. I created two italic character styles, one for the head on the page and one for the TOC: head_italic and toc_italic. They are different, of course, since the TOC font size is smaller than the head style on the page. To avoid messing with the TOC once it is built, I search for head_italic and replace it with toc_italic throughout the document before I build the TOC. When I do build the TOC, the italic text in the TOC already matches the main entry. Then I reverse the search and replace by looking for toc_italic character style together with the head paragraph style and change the found set back to head_italic. It is cumbersome, I know. It will be my new method until InDesign TOC builder comes with the ability to swap one character style with another on the fly. Dare I hope?

  • >