Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to insert TOC section numbers into section headers with PDF export?

Rick Suel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 24, 2013
I'm sure everyone has faced this problem, and hopefully it's been solved. When exporting to pdf, confluence automatically creates section numbers in the table of contents. I want those auto generated section numbers to be inserted at the beginning of the actual section titles in the document. Surely this is possible? Any help is greatly appreciated! -Rick

1 answer

0 votes
Steffen Heller
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 17, 2013

This must be defined in the PDF export stylesheet with the help of CSS counters. A quick example would look like this:

body {
counter-reset: levelA;
}
h2:before {
content: counter(levelA) ". ";
counter-increment: levelA;
}
h2 {
counter-reset:levelB;
}
h3:before {
content: counter(levelA) "." counter(levelB) ". ";
counter-increment: levelB;
}
Rick Suel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 10, 2013

This almost works, but still results in odd numbering. Thanks for the info though, this is a starting point.

Maurice Pasman January 25, 2016

Yeah, this fails in situations where h1-h6 markings are also used on the pages itself.

Steffen Heller
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 26, 2016

If so, just exclude those headings and include the page title instead.

Maurice Pasman January 26, 2016

How can those headers be detected (and thus excluded)?

Steffen Heller
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 26, 2016

Use .pagetitle h1 to only include the page title but not the page headings.

Gunnar Djurberg
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 12, 2017

I have a working example of plain html with levels of headings that get numbered (try here https://jsfiddle.net/gudj/37pcs28x/ )

body {counter-reset: lvl1;}
.pagetitle>h1   {counter-reset: lvl2;}
.pagetitle>h2   {counter-reset: lvl3;}
.pagetitle>h3   {counter-reset: lvl4;}
.pagetitle>h1 {counter-increment: lvl1;}
.pagetitle>h2 {counter-increment: lvl2;}
.pagetitle>h3 {counter-increment: lvl3;}
.pagetitle>h4 {counter-increment: lvl4;}
.pagetitle>h1:before {content: counter(lvl1) ". "}
.pagetitle>h2:before {content: counter(lvl1) "." counter(lvl2) ". "}
.pagetitle>h3:before {
content: counter(lvl1) "." counter(lvl2) "." counter(lvl3) ". "
}
.pagetitle>h4:before {
content: counter(lvl1) "." counter(lvl2) "." counter(lvl3) "." counter(lvl4) ". "
}

But when I use that CSS in "pdf export CSS" I get a couple of problems: The counter increment only works on the h1 level. For the lower levels (h2-h4) there is only one increment so they all show "1" (unless the parent level is missing in which case it becomes "0"). This one is quite annoying since I know the header levels are there since the content gets inserted. Could this be caused by counter reset caused by additional h1 tags? But why would they be wrapped in pagetitle class if they are not themselves page titles?

The second problem is discussed above by Heller etc - but I am not able to use pagetitle to filter out the headings within each page, the class seems to get matched also for some "intra-page" headlines, not just the page title. I've tried using other classes/ids from the displayed HTML but it seems only pagetitle is used in the pdf export...

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events