4

I am looking for a method to set the minimum number of pages for the TOC.

For example, with the MWE, chapter 1 starts on the 3rd page in first run, and the 14th page on second run. Knowing this I would like to get the first run to also start chapter 1 on the 14th page by inserting a sufficient number of blank pages for the TOC. In the second run, there should be 0 pages inserted (at least in this case since I reserved the correct number of pages).

Background:

This bug is causing me quite a bit of grief: "pgf Error: No shape named i-0 is known", but only upon 2nd run. The problem seems to be related to the number of pages used by the TOC changing between runs. So was hoping that something like this can be used as a temporary fix until the bug in the intersections library is fixed.

Code:

\def\NumberOfChapters{10}
\def\NumberOfSections{50}

\documentclass{book}
\usepackage{lipsum}
\usepackage{pgffor}

\begin{document}
\frontmatter
\pagenumbering{roman}
\tableofcontents
\pagenumbering{arabic}
\clearpage

\mainmatter
\foreach \x in {1,...,\NumberOfChapters}{
    \chapter{Chapter \x}
    \foreach \y in {1,...,\NumberOfSections}{
        \section{Section \y}
        \lipsum[1-7]
    }
}
\end{document}
4
  • 1
    Perhaps add \foreach\x in {\value{page},...,14}{\vbox{}\newpage}? Feb 2, 2012 at 3:51
  • @BrunoLeFloch: That does it. If you use \tableofcontents\cleardoublepage \foreach\x in {\value{page},...,14}{\vbox{}\newpage} \pagenumbering{arabic} the chapters are set "in place." Note that using \pagenumbering resets the page value to 1, so it should be issued after the "magic formula."
    – Werner
    Feb 2, 2012 at 4:11
  • @BrunoLeFloch (and Werner): You guys are geniuses!! Yes, this solves this problem and the one that has the bounty. If you guys want to post that as a solution to these two questions, you'll get the bounty. (Joseph deserves some credit too but not sure if a bounty can be split). Feb 2, 2012 at 4:23
  • @Werner go for it. I'm too busy with physics to write more than a two-line answer, which would be a real shame. Feb 2, 2012 at 4:52

1 Answer 1

3

Using Bruno's suggestion, the following works, setting Chapter 1 on (absolute) page 14, regardless of the compilation:

\def\NumberOfChapters{10}
\def\NumberOfSections{50}

\documentclass{book}
\usepackage{lipsum}
\usepackage{pgffor}

\begin{document}
\frontmatter
\pagenumbering{roman}
\tableofcontents
%\pagenumbering{arabic}
\cleardoublepage

\foreach\x in {\value{page},...,14}{\vbox{}\newpage}% Insert up to absolute page #14.

\pagenumbering{arabic}

\mainmatter
\foreach \x in {1,...,\NumberOfChapters}{
    \chapter{Chapter \x}
    \foreach \y in {1,...,\NumberOfSections}{
        \section{Section \y}
        \lipsum[1-7]
    }
}
\end{document}

Note that using \pagenumbering resets the page value to 1, so it should be issued after the "magic formula."

3
  • The solution to this also provides a work around for pgf error no shape named i 0 is known but only upon 2nd run. Do you want to post something there so you can get the bounty (half if I can figure out hot to split it between this workaround solution and Joseph's response)? Feb 2, 2012 at 8:02
  • @PeterGrill: I've added an answer to the linked post; thanks. As I mentioned to @cmhughes a little while back: "We should develop a rep-sharing program." :)
    – Werner
    Feb 2, 2012 at 16:21
  • Yeah, would be nice to be able to split the bounty between you and Joseph but from what I read up on last night it does not look like I can do that. Testing solution now... Feb 2, 2012 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .