none
Alternate Table of Contents format RRS feed

  • Question

  • Does anyone know of a way (macro or otherwise) to create multiple options for table of content formatting? I'm particularly looking to be able to customize the line spacing in the ToC entries.

    Our default ToC field code is: {TOC \o "1-4" \h \z \u \t }. Our default ToC style specifies 12 pt line space before and 6 pt line space afterwards – which is fine for some projects.  However, some projects need ToCs with 0 pt line space before and 0 pt line space afterwards.

    I’m only aware of a couple of manual solutions:

    * Highlight the ToC after it’s generated and manually redefine the line spacing to be 0 pt.  (However, doing this can cause the page numbers to be off, especially if the ToC loses one or more pages in the “compacting line spacing” process.)

    * Manually redefine the ToC style every time you want it to be 0 pt – and then remember to put it back to 12 pt before and 6 pt after when finished.  (This is a very time-consuming process, particularly if you’re switching between ToC styles frequently.  And there's a potential for confusion among end users.)

    Any suggestions for making this formatting change more automated?  Like perhaps a "compact ToC macro" vs a "regular default ToC" macro?

    Thanks!

    Thursday, February 14, 2013 8:25 PM

Answers

  • A macro to toggle the TOC Styles between between 6 & 12 pt is quite simple:

    Sub ToggleTOC()
    Dim i As Long, TOC As TableOfContents
    With ActiveDocument
    For i = 1 To 9
      With .Styles("TOC " & i).ParagraphFormat
        .SpaceAfter = .SpaceAfter Mod 6 + 6
        .SpaceBefore = .SpaceBefore Mod 12 + 6
      End With
    Next
    For Each TOC In .TablesOfContents
      TOC.Update
    Next
    End With
    End Sub

    Simply place the macro in the document's template and it will be available to all documents based on that template.

    The concern I have with this approach is that it only gives you two choices. It doesn't allow for different before/after spaces for different TOC styles and you can only have both a 6pt before and 12pt after setting, or 0 for both. Furthermore, if you run it on a document that has had some TOC styles modified but not others, or that use before/after spacings that are not multiples of 6pt, you might get some odd results. That's why I believe the template/organiser approaches are better.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by dogwoodnc Friday, February 15, 2013 1:06 PM
    Thursday, February 14, 2013 11:57 PM

All replies

  • Instead of trying to modify the TOC styles each time, you should consider having a separate template for each requirement.

    Alternatively, you could store your alternate TOC Styles in another document and use the Organiser to copy them into the documents that require them. This process could be automated, but the separate templates approach is better.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, February 14, 2013 9:54 PM
  • Thanks! Yes, that'd work... but I need to think about it a bit.  The vast majority of our docs (more than 95% at this time, but possibly less as more exception projects come in) -- many of which have their own templates -- are based on our 'default' styles; the styles are currently defined in a template that lives in our startup file, so we don't have to redefine it for each template.  (That way, too, if it needs to change, we only have to change it one place, i.e., in startup.)

    Thinking out loud, could I maybe use a macro to redefine the section heading & ToC styles for the current doc -- and somehow have them stay with the doc, overriding the defaults?  (I haven't thought that through or experimented with that idea yet....)

    Thanks again!  Your answer has helped me to think more broadly. :) 

    Thursday, February 14, 2013 11:12 PM
  • A macro to toggle the TOC Styles between between 6 & 12 pt is quite simple:

    Sub ToggleTOC()
    Dim i As Long, TOC As TableOfContents
    With ActiveDocument
    For i = 1 To 9
      With .Styles("TOC " & i).ParagraphFormat
        .SpaceAfter = .SpaceAfter Mod 6 + 6
        .SpaceBefore = .SpaceBefore Mod 12 + 6
      End With
    Next
    For Each TOC In .TablesOfContents
      TOC.Update
    Next
    End With
    End Sub

    Simply place the macro in the document's template and it will be available to all documents based on that template.

    The concern I have with this approach is that it only gives you two choices. It doesn't allow for different before/after spaces for different TOC styles and you can only have both a 6pt before and 12pt after setting, or 0 for both. Furthermore, if you run it on a document that has had some TOC styles modified but not others, or that use before/after spacings that are not multiples of 6pt, you might get some odd results. That's why I believe the template/organiser approaches are better.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by dogwoodnc Friday, February 15, 2013 1:06 PM
    Thursday, February 14, 2013 11:57 PM
  • Thank you!!! I do understand your recommendations that the template approach would be superior -- and agree for most scenarios -- but for our particular purposes and scenarios, the macro approach will be perfect.  I've modified it a bit so I have two separate macros, giving me two choices -- one to "compact" it (with line spacing at 0), and one to put it back to the original line spacing, should the project needs change.  For our purposes, those would be the only two valid choices. 

    Your answer was exactly what I needed!

    Thanks again!

    Friday, February 15, 2013 1:13 PM