Skip to main content
Participant
April 11, 2022
Answered

Autogenerated book TOC numbering problems

  • April 11, 2022
  • 3 replies
  • 490 views

Hi, 

 

I'm trying to add numbering to the autogenerated TOC in pdf-book output. Using css classes a.pdf-toc-level-2 and a.pdf-toc-level-3. I'm able to style the two levels of the toc (not sure why level-2 is the main chapters and where level-1 is, but that's not an issue). Counter for the main chapters (level2) is fine, but I need to reset the numbering of lvl3 for each main-chapter to display correct numbers.

 

What I want:

1 - ChapterA

  1 - subchapterAA

  2 - subchaterAB

2 - ChapterB

  1 - subchapterBA

  2 - subchapterBB

  3 - subchapterBC

3 - ChapterC

  1 - subchapterCA

 

What I get:

1 - ChapterA

  1 - subchapterAA

  2 - subchaterAB

2 - ChapterB

  3 - subchapterBA

  4 - subchapterBB

  5 - subchapterBC

3 - ChapterC

  6 - subchapterCA

 

I can't use nested counters that would work for classic <ol><li> lists since this TOC doesn't have this hierarchy, or at least I didn't find any by testing different styles. I think it's all just separate <a> lines? Counter-reset is scoped, so it doesn't work for this case. I've tried to use the counter-set attribute which works in most browsers and snippets, but the Robohelp shows it in red when editing and ignores it in output. I assume that Robohelp export does not support this? Does anyone have any experience styling and numbering the auto-generated TOC for book style output or any idea how should I go about this?

 

Fiddle test: https://jsfiddle.net/z52brmn9/

 

My css:

 

body {

  counter-reset: a-toc-level-2 0 a-toc-level-3 0;

}

 

a.pdf-toc-level-2:before {

  counter-increment: a-toc-level-2;

  content: counter(a-toc-level-2, decimal);

  padding-right: 0.5rem;

  counter-set: a-toc-level-3 0;

}

a.pdf-toc-level-3:before {

  counter-increment: a-toc-level-3;

  content: counter(a-toc-level-3, decimal);

  padding-right: 0.5rem;

}  

    This topic has been closed for replies.
    Correct answer Surbhi_Maheshwari17103204

    Hi,

     

    To achieve the mentioned TOC, you need to restart numbering for every h2 which is just after h1.

    Try this:

    body {
    counter-reset: a\.pdf-toc-level-1 0 a\.pdf-toc-level-2 0;
    }
    a.pdf-toc-level-1:before {
    counter-increment: a\.pdf-toc-level-1;
    content: counter(a\.pdf-toc-level-1, decimal);
    padding-right: 0.5rem;
    }
    a.pdf-toc-level-2:before {
    counter-increment: a\.pdf-toc-level-2;
    content: counter( a\.pdf-toc-level-2, decimal);
    padding-right: 0.5rem;
    }

    a.pdf-toc-level-1 + a.pdf-toc-level-2 {
    counter-reset: a\.pdf-toc-level-2 0;
    }

     

    This should give you the TOC you are looking for 🙂
    Let us know how it goes. 

     

    Thanks and Regards,
    Surbhi Maheshwari

    3 replies

    Adobe Employee
    April 26, 2022

    Hi,

     

    To achieve the mentioned TOC, you need to restart numbering for every h2 which is just after h1.

    Try this:

    body {
    counter-reset: a\.pdf-toc-level-1 0 a\.pdf-toc-level-2 0;
    }
    a.pdf-toc-level-1:before {
    counter-increment: a\.pdf-toc-level-1;
    content: counter(a\.pdf-toc-level-1, decimal);
    padding-right: 0.5rem;
    }
    a.pdf-toc-level-2:before {
    counter-increment: a\.pdf-toc-level-2;
    content: counter( a\.pdf-toc-level-2, decimal);
    padding-right: 0.5rem;
    }

    a.pdf-toc-level-1 + a.pdf-toc-level-2 {
    counter-reset: a\.pdf-toc-level-2 0;
    }

     

    This should give you the TOC you are looking for 🙂
    Let us know how it goes. 

     

    Thanks and Regards,
    Surbhi Maheshwari

    Community Expert
    April 12, 2022

    Your best bet is probably to contact support using the email address here: https://helpx.adobe.com/contact/enterprise-support.other.html#robohelp

    Community Expert
    April 12, 2022

    In a  test project I added the first level style in like so:

    body {
      counter-reset: a-toc-level-1 0 a-toc-level-2 0 a-toc-level-3 0;
    }
    a.pdf-toc-level-1:before {
      counter-increment: a-toc-level-1;
      content: counter(a-toc-level-1, decimal);
      padding-right: 0.5rem;
      counter-set: a-toc-level-2 0;
    }
    a.pdf-toc-level-2:before {
      counter-increment: a-toc-level-2;
      content: counter(a-toc-level-2, decimal);
      padding-right: 0.5rem;
      counter-reset: a-toc-level-3 0;
    }
    a.pdf-toc-level-3:before {
      counter-increment: a-toc-level-3;
      content: counter(a-toc-level-3, decimal);
      padding-right: 0.5rem;
    }

    Which generated this:

    This is the book toc in my project if that helps:

     

    Community Expert
    April 12, 2022

    Oh wait, the second section didn't update. Never mind. 😕😕