TOC not working with custom styles
tpcarman opened this issue · 2 comments
I seem to have an issue whereby the TOC is not generated if I use custom style headings. The TOC heading is displayed correctly, however the section headings are not generated within the TOC.
`# Document Options
DocumentOption -EnableSectionNumbering -PageSize A4 -DefaultFont 'Segoe UI' -MarginLeftAndRight 72 -MarginTopAndBottom 72
# Styles
Style -Name 'Cover_H1' -Size 24 -Color 00B050 -Font 'Segoe UI' -Align Right
Style -Name 'Cover_H2' -Size 18 -Color 3F4243 -Font 'Segoe UI' -Align Right
Style -Name 'Cover_H3' -Size 12 -Color 3F4243 -Font 'Segoe UI' -Align Right
Style -Name 'Custom_H1' -Size 16 -Color 00B050 -Font 'Segoe UI'
Style -Name 'Custom_H2' -Size 14 -Color 00B050 -Font 'Segoe UI'
Style -Name 'Custom_H3' -Size 12 -Color 00B050 -Font 'Segoe UI'
Style -Name 'Custom_H4' -Size 11 -Color 3F4243 -Font 'Segoe UI'
Style -Name 'Custom_H5' -Size 10 -Color 3F4243 -Font 'Segoe UI' -Italic
Style -Name 'Normal' -Size 10 -Font 'Segoe UI' -Default
Style -Name 'TOC' -Size 16 -Color 00B050 -Font 'Segoe UI'
Style -Name 'Custom_TableHeading' -Size 10 -Color FFFFFF -BackgroundColor 7F7F7F -Font 'Segoe UI'
Style -Name 'Custom_TableRow' -Size 10 -Font 'Segoe UI'
Style -Name 'Custom_TableAltRow' -Size 10 -BackgroundColor DDDDDD -Font 'Segoe UI'
TableStyle -Id Custom -HeaderStyle Custom_TableHeading -RowStyle Custom_TableRow -AlternateRowStyle Custom_TableAltRow -BorderColor 7F7F7F -Align Left -BorderWidth 0.5 -Default`
TOC -Name 'Table of Contents'
Section -Style Custom_H1 'Section 1' { Paragraph 'Section 1 paragraph text.' Section -Style Custom_H2 'Section 1.1' { Paragraph 'Section 1.1 paragraph text.' }
If I revert back to default Styles/Headings then everything works as expected.
Hi @tpcarman Thanks for reporting. I think that the TOC in Word requires the use of the default Heading 1 - 3 styles (or at least the default implementation does).
Here's an example of overriding the built-in heading styles:
document Test {
Style -Name 'Heading 1' -Size 16 -Color 00B050 -Font 'Segoe UI'
Style -Name 'Heading 2' -Size 14 -Color 00B050 -Font 'Segoe UI'
TOC
Section 'Section1' -Style Heading1 {
Paragraph 'Test Section1';
Section 'Section2' -Style Heading2 {
Paragraph 'Test Section2';
}
}
} | Export-Document -Path $env:TEMP -PassThru -Format Word | Invoke-Item
Does this help? If not, we will need to review the WordML documentation to see if using other styles is supported.
Hi @iainbrighton ,
It seems TOC does not work with custom heading names, however if I use the default heading names with customised style parameters as you have demonstrated, then it works as expected.
Thank you for resolving this issue for me.