18 Replies Latest reply: Jul 9, 2012 2:39 AM by P Spier RSS

    Manipulate table of contents results

    gwhPoster Community Member

      Hi everyone,

      Within each chapter of a book I’m working on, there are level 1 headings that look like the following:

       

      ¶5-100 Context

       

      So each of these headings has a paragraph number, ie. ¶5-100 and then the name of the heading, ie. Context. There’s a tab between the para number and the content of the heading.

      I need to create a specific chapter by chapter table of contents using the content of these level 1 headings. The information will be located at the start of each chapter.

      It’s easy enough to do but when the TOC is genereated I get the following effect:

       

      ¶5-100 Context  [tab]    page number

      ¶5-120 next heading   [tab]   page number

      ¶5-140 next heading   [tab]   page number

      ¶5-160 next heading   [tab]   page number

       

      I don’t need the page numbers at all and instead of the above, I need the following result:

       

      Context [tab] ¶5-100

      next heading [tab] ¶5-120

      next heading [tab] ¶5-140

      next heading [tab] ¶5-160

       

      Once I have the above effect, I would then go ahead and create cross references where the para numbers within the TOC are the source of the Xref and the destination is the relevant heading within the body of the chapter.

       

      So is there a way to manipulate the results so that the headings appear as the above? I know it probably can’t be done but just thought I’d ask incase I’m missing something.

       

      Appreciate any help.

        • 1. Re: Manipulate table of contents results
          P Spier CommunityMVP

          I don't think you can do it with a standard TOC by itself, but you might be able to do it with cross-references, or maybe using a standard TOC in combination with character style-based running head variables that would populate non-printing frames to be included in the TOC. That method would only work, though, for one heading per page.

          • 2. Re: Manipulate table of contents results
            gwhPoster Community Member

            There are more than one level 1 headings per page so as you mentioned it may not work.

             

            It looks like i'm going to have to do a bit of post-TOC manual manipulation which will unfortunately take more time.

             

            Thanks anyway for the advice.

            • 3. Re: Manipulate table of contents results
              P Spier CommunityMVP

              Well it wouldn't be hard to set up a GREP query for find/change that would move the numbers after making the TOC. Downside is you'de have to do it each time you update.

              • 4. Re: Manipulate table of contents results
                gwhPoster Community Member

                The GREP query sounds good. Can you supply the code as I don't have much experience with GREP.

                • 5. Re: Manipulate table of contents results
                  P Spier CommunityMVP

                  try

                   

                  ^(\d+-\d+)\s(.+)

                   

                  and change to $2\t$1

                  • 6. Re: Manipulate table of contents results
                    gwhPoster Community Member

                    It said it couldn't find a match. Maybe this was because I revised the TOC style so that it didn't include any numbers. The result now looks like this:

                     

                    ¶5-105 [tab] heading content

                     

                    Would this make a difference to the GREP code?

                    • 7. Re: Manipulate table of contents results
                      P Spier CommunityMVP

                      Are you on the GREP tab or the Text tab of the Find/Change dialog? I often make the mistake of entering GREP queries in the text search and it takes me awhile to figure out why no match is found.

                       

                      Can you post a screen cap of the un-altered TOC with hidden characters showing? Might be something at the start of the line you didn't mention. Or perhaps I misinterpreted and you really have the pilcrow there as part of the text? for that change the find to ^(~7\d+-\d+) (.+)

                      • 8. Re: Manipulate table of contents results
                        gwhPoster Community Member

                        The forums won't let me insert an image - the insert image button is greyed out after I navigate for the file on my computer.

                         

                        I'm definitely on the GREP tab. There's nothing at the start of the line. Not sure what a pilcrow is? There's that para symbol there at the start of the text if that's what you mean.

                         

                        I tried your revised code but again no luck. Can you point out what the code means so maybe I can decipher why it's not working?

                         

                        Thanks again

                        • 9. Re: Manipulate table of contents results
                          gwhPoster Community Member

                          Sorry I spoke too soon. I revised your code from this:

                           

                          ^(~7\d+-\d+) (.+)

                           

                          to this:

                           

                          ^(~7\d+-\d+)(.+)

                           

                          ie. I removed a space and it seems to have nearly worked. The entries now look like this:

                           

                          [tab] heading content [tab] ¶5-105

                           

                          So it's nearly there but the result is that it's putting an extra tab before the heading content.

                           

                          Is there a way to remove that?

                          • 10. Re: Manipulate table of contents results
                            P Spier CommunityMVP

                            Sorry, Looks like I didn't catch Jive changing the \s to a space when I copied the query. You want ^(~7\d+-\d+)\s(.+)

                             

                            That translates to at the start of a paragraph find (a pilcrow [paragraph mark] followed by one or more digits, a hyphen,then one or more digits) any whitespace (any characters up to the end of the paragraph).

                             

                            The replace is the any characters expression, a tab, and the pilcrow/digits group, and the 'any white space' is thrown away.

                            • 11. Re: Manipulate table of contents results
                              gwhPoster Community Member

                              For some reason if I add \s to the code, it doesn't work. I have to remove that space so it's like this:

                               

                              ^(~7\d+-\d+)(.+)

                               

                              ...but I'm still getting the tab at the beginng of the results:

                               

                              [tab] heading content [tab] ¶5-105

                               

                              Can I do something to remove the tab as part of the query?

                              • 12. Re: Manipulate table of contents results
                                P Spier CommunityMVP

                                ^(~7\d+-\d+)\s(.+) works here, and should work for you, too. Make sure you typed it correctly.

                                 

                                If it doesn't work, try \t in place of \s (\t is the tab character, \s is any whitespace, so a bit more versatile).

                                • 13. Re: Manipulate table of contents results
                                  [Jongware] CommunityMVP

                                  \s picks up a single space/tab -- perhaps there is more than one? Try with \s+ ("one or more white space").

                                  • 14. Re: Manipulate table of contents results
                                    gwhPoster Community Member

                                    The following works perfectly:

                                     

                                    ^(~7\d+-\d+)\s(.+)

                                     

                                    Thanks so much.

                                    • 15. Re: Manipulate table of contents results
                                      gwhPoster Community Member

                                      Could I ask another related question? I've got my TOC looking like this now:

                                       

                                      heading content [tab] ¶5-105

                                       

                                      How would I create a nested style so that the ¶5-105 is coloured separately from the rest of the TOC entry? I've looked into the nested styles but it only lets you target areas "up to" or "through". How can I say colour everything "after the tab"?

                                       

                                      Appreciate any further help.

                                      • 16. Re: Manipulate table of contents results
                                        [Jongware] CommunityMVP

                                        a. Use this GREP style:

                                         

                                        (?<=\t).+

                                         

                                        This will look for a tab, then apply a character style of your choice to the rest of the line, excluding the tab (which might be important if you apply underlining).

                                         

                                        GREP styles are my favourite because I can express virtually everything I need with those -- they are so versatile! However:

                                         

                                        b. Use this Nested Style:

                                         

                                        [None] through 1 [Tab Characters]

                                        yourStyle up to 5 [Words]

                                         

                                        (The latter number is because I'm not sure how InDesign counts 'words'. There doesn't seem to be a "Up to End Of Line" code.)

                                        • 17. Re: Manipulate table of contents results
                                          gwhPoster Community Member

                                          That's great - I'll experiment with both options.

                                           

                                          Thanks so much for your help.

                                          • 18. Re: Manipulate table of contents results
                                            P Spier CommunityMVP

                                            [Jongware] wrote:

                                             

                                            b. Use this Nested Style:

                                             

                                            [None] through 1 [Tab Characters]

                                            yourStyle up to 5 [Words]

                                             

                                            (The latter number is because I'm not sure how InDesign counts 'words'. There doesn't seem to be a "Up to End Of Line" code.)

                                            When I want to run a nested style up to the end of a paragraph in a situation like this I often just tell it to run up to an end nested character style marker and don't insert one. You can use any character that isn't encountered and the nested style will run to the end of the paragraph. In this particular case you could also "swap" the formatting and define the paragraph style the way you want the numbers to look, then apply a nested style through 1 tab to change the text ahead of it, then there's no need for a "none."