Skip to main content
Inspiring
February 16, 2023
Question

Numbered headings in PDF output only

  • February 16, 2023
  • 2 replies
  • 598 views

Hi everyone,

I'm having trouble with numbered headings in my PDF output (RH 2022.0.346).

My goal:

I have content which is output into HTML as well as PDF. For HTML, I don't need numbered headings. For PDF, I do. It should look something like

1 Heading 1

1.1 Heading 2

1.2 Another heading 2

1.2.1 Heading 3

... you get the idea.

I have tried to do this in the layout.css of my PDF output using counters. Currently, my css looks as follows:

body {
  font-family: 'IBM Plex Sans';
  font-size: 9pt;
  counter-reset: ebene1 ebene2 ebene3 ebene4;
}
h1 {
  font-size: 17pt;
  counter-increment: ebene1;
  counter-reset: ebene2 ebene3 ebene4;
}
h2 {
  font-size: 13pt;
  counter-increment: ebene2;
  counter-reset: ebene3 ebene4;
}
h3 {
  font-size: 11pt;
  counter-increment: ebene3;
  counter-reset: ebene4;
}
h4 {
  font-size: 10pt;
  counter-increment: ebene4;
}
h5 {
  font-size: 9pt;
}
h1:before {
  counter-reset: ebene2 ebene3 ebene4;
  content: counter(ebene1) " ";
}
h2:before {
  counter-reset: ebene3 ebene4;
  content: counter(ebene1) "." counter(ebene2) " ";
}
h3:before {
  counter-reset: ebene4;
  content: counter(ebene1) "." counter(ebene2) "." counter(ebene3) " ";
}
h4:before {
  content: counter(ebene1) "." counter(ebene2) "." counter(ebene3) "." counter(ebene4) " ";
}

I have tried different guides on counters in CSS on the internet and I'm not sure whether I'm doing something wrong or Robohelp is messing something up on output, because my TOC looks like the picture attached... 

Anybody got an idea how I can fix this?

    This topic has been closed for replies.

    2 replies

    Inspiring
    February 17, 2023

    I toyed around with this syntax a lot. I got different results, sometimes, but it always contained errors.

    So I tried a different approach: I used the "Autonumber" feature in Robohelp. If you enable it, RH includes wrong syntax at first (it enters <0> instead of <x>, but that was easily fixed). However, after publishing it, the numbering is still wrong. So I guess, this is a problem of Robohelp, or does anyone see a way to fix this?

     

    By the way, the numbering in the TOC and the numbering throughout the documents is not the same. For example, chapter 2.2 in the TOC is wrongly numbered as 2.1 (again) and within the respective chapter, it is 2.2. The numbering is still wrong in places throughout the document, though.

     

    My colleague is currently trying my project in the new prerelease, hoping they will have fixed the PDF output there, as well as with different content but the same CSS, in case something there is messed up. But it doesn't look like that is going to work, either.

     

    Here's the code Robohelp produced (I only changed <0> to <x>) as well as the published TOC:

    body {
      font-family: 'IBM Plex Sans';
      font-size: 9pt;
      counter-reset: h11 0 h21 0 h31 0 h41 0;
    }
    h1 {
      font-size: 17pt;
      counter-reset: h21 0;
      --autonumber: autonumber;
      margin-left: calc(var(--list-indent) + var(--prefix-size) + var(--prefix-gap));
      --prefix-size: 24px;
      --prefix-fixed-size: 0;
      --prefix-gap: 4px;
      --vertical-spacing: 0px;
      --list-indent: 0px;
      position: relative;
      margin-top: calc(var(--vertical-spacing) / 2);
      margin-bottom: calc(var(--vertical-spacing) / 2);
    }
    h2 {
      font-size: 13pt;
      counter-reset: h31 0;
      --autonumber: autonumber;
      margin-left: calc(var(--list-indent) + var(--prefix-size) + var(--prefix-gap));
      --prefix-size: 48px;
      --prefix-fixed-size: 0;
      --prefix-gap: 4px;
      --vertical-spacing: 0px;
      --list-indent: 0px;
      position: relative;
      margin-top: calc(var(--vertical-spacing) / 2);
      margin-bottom: calc(var(--vertical-spacing) / 2);
    }
    h3 {
      font-size: 11pt;
      counter-reset: h41 0;
      --autonumber: autonumber;
      margin-left: calc(var(--list-indent) + var(--prefix-size) + var(--prefix-gap));
      margin-top: calc(var(--vertical-spacing) / 2);
      margin-bottom: calc(var(--vertical-spacing) / 2);
      --prefix-size: 48px;
      --prefix-fixed-size: 0;
      --prefix-gap: 4px;
      --vertical-spacing: 0px;
      --list-indent: 0px;
      position: relative;
    }
    h4 {
      font-size: 10pt;
      --autonumber: autonumber;
      margin-left: calc(var(--list-indent) + var(--prefix-size) + var(--prefix-gap));
      margin-top: calc(var(--vertical-spacing) / 2);
      margin-bottom: calc(var(--vertical-spacing) / 2);
      --prefix-size: 48px;
      --prefix-fixed-size: 0;
      --prefix-gap: 4px;
      --vertical-spacing: 0px;
      --list-indent: 0px;
      counter-reset: h51 0;
      position: relative;
    }
    h5 {
      font-size: 9pt;
      position: relative;
    }
    h1:before {
      counter-increment: h11;
      content: counter(h11, decimal)" ";
      text-align: right;
      position: absolute;
      left: calc(-1 * var(--prefix-size) - var(--prefix-gap));
      margin-right: var(--prefix-gap);
      width: var(--prefix-size);
      overflow: hidden;
    }
    h2:before {
      counter-increment: h21;
      content: counter(h11, decimal)"." counter(h21, decimal)" ";
      text-align: right;
      position: absolute;
      left: calc(-1 * var(--prefix-size) - var(--prefix-gap));
      margin-right: var(--prefix-gap);
      width: var(--prefix-size);
      overflow: hidden;
    }
    h3:before {
      counter-increment: h31;
      content: counter(h11, decimal)"." counter(h21, decimal)"." counter(h31, decimal)" ";
      text-align: right;
      position: absolute;
      left: calc(-1 * var(--prefix-size) - var(--prefix-gap));
      margin-right: var(--prefix-gap);
      width: var(--prefix-size);
      overflow: hidden;
    }
    h4:before {
      counter-increment: h41;
      content: counter(h11, decimal)"." counter(h21, decimal)"." counter(h31, decimal)"." counter(h41, decimal)" ";
      text-align: right;
      position: absolute;
      left: calc(-1 * var(--prefix-size) - var(--prefix-gap));
      margin-right: var(--prefix-gap);
      width: var(--prefix-size);
      overflow: hidden;
    }

    Any ideas on how to possibly fix this would be greatly appreciated! 🙂

    Inspiring
    February 17, 2023

    Sorry, I forgot to include the screenshot from within RH.

    Jeff_Coatsworth
    Community Expert
    Community Expert
    February 16, 2023

    Two layers of headings - one without numbering; one with - conditioned for PDF only?

    Inspiring
    February 17, 2023

    Sorry, I don't understand what you're trying to say.

    I have a completely different css for my PDF output, see above. My HTML output is not connected to my above css, it has got its own.