Table of Content Page Numbers Are Off

I’m generating a table of contents by selecting the necessary documents in the binder, and doing a Copy Special to copy as ToC. When I compile, the Table of Contents is generated, but most or all of the page numbers are slightly off. For example, something that starts on page 9 says page 8 in the ToC, or something that starts on page 15 says page 13 in the ToC. I tried to see if one particular entry was causing it get off, but it doesn’t seem to be consistent. Sometimes, the very first entry in the ToC is off by a page or two. I’m not sure if it’s not accounting correctly for the length of the ToC itself, or if something else is going on. I’ve tried compiling to PDF, DOC, DOCX, and RTF, and the results were similar for all of them.

Below is the process I use to generate a ToC for PDF files. Step 1 is usually the reason that I find the page numbers off.
File => Page Setup look the same Compile => Page Settings => Page Setup
but appear to act differently.

For printed output, as the final step before publication, you must create it manually. Traditionally all Front Matter pages, except for Copyright page, start on odd-numbered right-hand Recto pages. The Copyright page is always on the back of the Title page. Many authors add blank pages to the front matter to force pages to start on a recto page. See section Front Matter vs Recto Pages for a better way to do this.

These are the steps to generate the TOC manually:
1. Go to File => Page Setup and make sure that your page size is set to the size of your actual planned output! Warning: Compile => Page Settings => Page Setup looks the same but appears not cause the TOC to be generated for the current page size when using Edit => Copy Special => Copy as TOC.
2. Go to Compile => Transformations and make sure that “Remove all hyperlinks” is unchecked. If checked then the page numbers will display as <$p> rather than as an actual link to the page number. Many authors have struggled to figure out this problem with their TOCs.
3. In your Front Matter folder, create a blank text document called Table of Contents, add a title and format it at the top then add couple blank lines, making sure that these paragraphs are left aligned and are of the font and type size of your body text. Make sure that the new page has Include in Compile, Page Break Before, and Compile As-IS checked in the Inspector Pane.
4. In the Binder, select the items you want in the TOC. You may need to expand folders and containers if you want a multi-level nested TOC. You can select one-at-a-time, or select the first thru the last. The contents of unexpanded folders will not show in the TOC.
5. Go to Edit => Copy Special => Copy Documents as ToC
6. Go to the recently created TOC page, position yourself at the bottom and paste using Edit => Paste and Match Style.
7. If you want the Front Matter pages in your TOC, you will have to copy-and-paste twice.
8. Do a compile and check the results. If you drag the tab-stop for the page number to the left, you will loose the indenting at the left. Then you will have to add your own tab stops and re-indent each line. I set my tab stops at 3/16, 3/8, 9/16”. For 100 items it is not fun, but it works.
9. Look for any lines where the page-number tag requires and extra tab to be properly aligned and fix.

I say that creating the TOC is the final step before publishing in PDF format. I don’t mean that you shouldn’t manually create one several times before then. If your Chapter and Section titles are too long they can really mess your a TOC. You should make a TOC for the actual size of your book and if titles are more than one line consider a shorter title.

Warning: Because the process of making the TOC is decoupled from the compile-process, it is possible to have one or more entries where page numbers are shown as “??”. This is likely because they don’t have “Include in Compile” checked or have been renamed or deleted since they were pasted.

These instructions got me a lot closer, but it still gets off after a while. For the first 79 pages, it seems to work correctly now. But I have a heading near the bottom of page 79, about 4 lines from the end of the page, but the ToC lists it as appearing on page 80. The entries that follow are all progressively off as a result.