About Arbortext Styler > Working with Tables of Contents > Styling an Element to Generate a Table of Contents
  
Styling an Element to Generate a Table of Contents
This topic describes how to style an element so it generates a table of contents in your document's final output. There are two examples listed - the first one uses the default table of contents element in a document type whilst the second shows you how to specify that any element in your document type can be used to output a table of contents.
Example: Styling a toc Element to Generate a Table of Contents
1. In Arbortext Editor, open the transport.xml document located at Arbortext-path/samples/styler.
2. Choose Styler > New Stylesheet to create a new stylesheet.
3. In Arbortext Styler, select the chapter element in the Elements list.
4. Choose Division as the style for the element, via the Edit > Style menu option. Click OK in the Division Details dialog box to accept 1 as its division level.
Here you have specified that chapter elements should constitute the divisions in your document, and that they should be classed as level 1 in the document's division hierarchy.
5. Select the toc element in the Elements list.
6. Choose Table of Contents as the element's style. The Table of Contents Details dialog box opens.
7. Select the table of contents format object that contains the formatting you require. If the list is blank, you will need to create a new object.
8. Click OK to save the change and exit the dialog box. The selected table of contents format object is now associated with the toc element.
Note that the description of the toc element and its Generated text properties confirm that it is associated with the selected table of contents format object, in this case Chapter Table of Contents:
This is an image of the Description for the toc element, reading “Block, Gentext: Add After (JTTOC)”
This is an image of the generated text setting for the toc element, reading “JTTOC” in the field
9. Choose Preview > Print.
In the Print Preview window, note that the table of contents displays after the first paragraph in the document.
You can create table of contents format objects and associate them with elements other than a toc element. This is helpful if your document type doesn't include a table of contents element.
Example: Styling a Block Element to Generate a Table of Contents
This example continues from the previous one, using the transport.xml sample file and the new stylesheet created in that example. Here the element authorblurb will be defined as a Table of Contents element and used to generate a table of contents based on the titles of sect1 elements.
1. In Arbortext Editor, locate the title element after the second chapter element.
2. Insert an authorblurb tag directly after the title element, before the first formalpara element.
3. In Arbortext Styler, create a new table of contents format object via the Insert > Table of Contents menu option. Name the object chapter and make the following changes:
Set the Scope to chapter. This creates a table of contents that will list all occurrences of the selected element(s) from the chapter in which it appears.
Deselect the Division titles option to specify that Arbortext Styler should not use the titles of all the divisions in your document (e.g. chapters) as table of contents entries.
Click the Customize button to open the Customize Table of Contents dialog box.
In the dialog box, check the Include box for the title in sect1 context.
Here you have confirmed that the chapter Table of Contents object should use all title in sect1 contexts in the chapter as its entries.
4. Back in the Elements list, select the authorblurb element.
5. Apply the Table of Contents style to the element. The Tables of Contents Details dialog box opens.
6. Select the chapter table of contents format object from the Select a table of contents list then click OK to exit the dialog box. The Description tab for the element and its Generated text properties show that the table of contents format object has been applied as generated text:
7. Choose Preview > Print.
In the Print Preview window, note that the chapter-level table of contents displays after the title of the second chapter.
You can modify a table of contents by adding division levels, changing its appearance, or adding generated text to a table of contents.
Example: Modifying a Table of Contents Format
This example continues from the previous one, using the transport.xml sample file and the new stylesheet created in that example.
1. In the Elements list, select the sect1 element.
2. Apply the Division style to the element via the Edit > Style menu option. The Division Details dialog box opens.
3. Set the Division Level to 2 then click OK to exit the dialog box.
4. Choose Preview > Print and review the document-level table of contents. You will see that an entry for the sect1 title is now displayed.
5. In Arbortext Styler, create a new table of contents format object via the Insert > Table of Contents menu option. Name the object chapter2 and make the following changes:
Set the Scope to chapter to create an alternative chapter-level table of contents format.
Deselect the Division titles option to specify that Arbortext Styler should not use the titles of all the divisions in your document (e.g. chapters) as table of contents entries.
Click the Customize button to open the Customize Table of Contents dialog box.
In the dialog box, check the Include box for the title in sect1 context.
Here you have confirmed that the chapter Table of Contents object should use all title in sect1 contexts in the chapter as its entries.
Choose Format... to open the Table of Contents Format dialog box.
Deselect the Leader dots option. Note how the display in the Print/PDF preview window changes.
Click OK to save the change and exit the dialog box.
6. In the Elements list, select the authorblurb element and choose the Generated text category.
7. Choose the Edit button for the After-text field to open the Generated Text Editor.
8. Place your cursor next to the Table of Contents element and choose Edit > Modify Attributes. The Modify Table of Contents dialog box opens.
9. Choose the chapter2 table of contents format object then click OK to exit the dialog box.
10. Choose File > Apply and Close to exit the Generated Text Editor. You will see that the Description tab for the element and its Generated text properties show that the setting has changed to use the chapter2 object as generated text:
11. Choose Preview > Print and review the chapter-level table of contents. You will see that leader dots no longer appear in the entries.