I have an ePub file that I generate in which I have chapters and sub-chapters.

I found here an example of how to create sub-chapters in the ncx file.

I quote here the answer of @macjohn

<meta content="2" name="dtb:depth"/>
<navPoint class="chapter" id="chapter1" playOrder="1">
  <navLabel><text>Chapter 1</text></navLabel>
  <content src="file1.xhtml"/>

  <navPoint class="subchapter" id="sub1" playOrder="2">
      <navLabel><text>Subchapter 1</text></navLabel>
      <content src="file2.xhtml"/>

The thing is that in my case the chapters are in xhtml files, but the sub-chapters are just within <h2> </h2> tags in the xhtml files of the chapters.

So my question is, how can I add sub-chapters in the ncx file based on the h2 tags and not on an external file ?

1 Answer 1


Calibre editor has a graphical interface that lets you edit the ToC of a given ebook file (the ToC editor itself is accesible also from the default window, without the need to open the full editor).

You can select different ways to create the ToC, I think that in your case you should experiment by selecting "major headings" or "all headings".

enter image description here

  • What I would like is to do it myself with auto generated files through another software. What I can probably do is to do it with Calibre and read it's output to understand how it is done.
    – HpTerm
    Jan 31, 2017 at 17:38
  • 1
    You probably need to set id's in your HTML files and link to those. Have a look here idpf.github.io/a11y-guidelines/content/xhtml/toc.html
    – Sekhemty
    Jan 31, 2017 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.