Creating a Table of Contents in Calibre
If you use ePub Split or convert PDFs to ePub or Mobi, many times a table of contents does not carry over. I like a TOC in electronic books because it helps me gauge where I am in a book and it helps me navigate. For some programs, it can even help in loading the ebook faster.
The easiest way (albeit not the fastest) way to create a Table of Contents in Calibre is to use the edit book feature and to auto generate a table of contents from the files. You can only edit books that are ePub or AZW. I prefer to convert to ePub and work from there.
Hiighlight your ebook and then click on edit.
A new screen will open. The first thing you want to do is create a checkpoint. A checkpoint preserves an image of the ebook before you start editing so if you really mess up you can return to the beginning. I believe a checkpoint is also created after every save. I like to save as I go. You can view the various checkpoints on the lefthand side. If you don’t see your checkpoints, go to View. Selection Checkpoints. A small dialogue box on the left side should appear.
On the left side column, you can view the files, stylesheets, checkpoints, table of contents. The middle window shows the HTML view of the ebook and the right column displays what the final book looks like. The design of the book is affected by the “stylesheet.” There may be images and finally at the bottom left there is the table of contents. This book has only a prologue in the TOC which isn’t effective or useful.
There are only four files. If I generate a table of contents based on “files”, I’ll only get this gibberish:
Those links aren’t useful either. What we want to do is to split the book at the chapter headings. Calibre’s edit book has an easy way to do this. At the bottom of the right column is split file icon.
Click on the icon and then drag it to the point where you want the file to split. Everything below the green line will go into the next file.
Continue this process until you’ve split the chapters into separate files. As you split the files, the table of contents generated expands as well:
Sometimes a file will end in the middle of the chapter. Highlight the content between the body tags and then paste it into one file.
Another way to split the files into chapters is to use XPath.
In this particular case, the XPath would be
This command will insert a split before every image tag with the class “calibre7” that is a child of a p tag that is a child of a body tag. If this makes no sense to you, just use the split tool in the preview screen described above.
Once your files are split, generate your table of contents. Go to Tools and select Edit Table of Contents.
On the right hand side, select Generate TOC from files.
Once you have generated your TOC, make sure you press the OK button in the bottom right or you will lose your changes. After you generated your TOC, check to see if you’ve made any errors. Here you can see I have two chapter 10s and two chapter 16s as well as part of another chapter. These errors occurred because I used the XPath in the middle of the process instead of the beginning. I’ll go and clean up the dups and then regenerate the ToC. It should be noted that when you regenerate your TOC, it does not erase the previous TOC but adds to it so be sure to remove all the TOC entries before generating the TOC again.
Happy TOC generating.
- You can rename a TOC entry by double clicking on the text of the TOC entry.
- You can use the split tool inside the TOC edit dialogue box. It’s not my preferred method because you have to manually enter each TOC name. If you use the generate tools then it will use the first text line of each file. In this case (and in most cases, it will be the chapter words (CHAPTER ONE / CHAPTER TWO) or the chapter numbers as in the example book).
- If you understand xPath you can create the TOC from an XPATH phrase. While that works, often you’ll end up with a number of “Untitled” TOC entries which I don’t find particularly helpful.