I've attached a patch that extends the existing test case with the scenario described in the issue. It fails with the following error:
[ERROR] Failures: [ERROR] AllIT$NestedPDFExportIT>PDFExportIT.numberedHeadings:623 expected: <NumberedHeadings 3 / 3 1 Heading 1 1.1 Heading 1-1 Heading without number 1.1.1 Heading 1-1-1 1.1.2 Heading 1-1-2 1.2 Heading 1-2 1.2.1 Heading 1-2-1 1.2.1.1 Heading 1-2-1-1 1.2.1.2 Heading 1-2-1-2 1.7 Heading 1-7 1.7.1 Heading 1-7-1 1.7.5 Heading 1-7-5 1.7.6 Heading 1-7-6 1.8 Heading 1-8 5 Heading 5 2 Heading 2 2.1 Heading 2-1 2.1.1 Heading 2-1-1 2.1.1.1 Heading 2-1-1-1 2.1.1.1.1 Heading 2-1-1-1-1 2.1.1.1.1.1 Heading 2-1-1-1-1-1 2.1.1.1.1.2 Heading 2-1-1-1-1-2 > but was: <NumberedHeadings 3 / 3 1 Heading 1 1.1 Heading 1-1 Heading without number 1.1.1 Heading 1-1-1 1.1.2 Heading 1-1-2 1.2 Heading 1-2 1.2.1 Heading 1-2-1 1.2.1.1 Heading 1-2-1-1 1.2.1.2 Heading 1-2-1-2 1.7 Heading 1-7 1.7.1 Heading 1-7-1 1.7.5 Heading 1-7-5 1.7.6 Heading 1-7-6 1.8 Heading 1-8 4 Heading 5 1 Heading 2 1.1 Heading 2-1 1.1.1 Heading 2-1-1 1.1.1.1 Heading 2-1-1-1 1.1.1.1.1 Heading 2-1-1-1-1 1.1.1.1.1.1 Heading 2-1-1-1-1-1 1.1.1.1.1.2 Heading 2-1-1-1-1-2 >