0

Is it possible to add a page break after the table of contents in the preamble rather than inline in the .tex file?

This question is somewhat related to the other one I asked here, though since it's a different question I thought I should do another post.

Basically I'm using Sphinx with Read the Docs, so I don't have access to the generated .tex file before it's processed into a PDF, meaning I have to make any changes I do to the preamble section.

My current doc class is "report", but the content starts on the same page as the last partial page of the table of contents, whereas I'd like to start it on the next page if that's possible?

Here's what I'm adding to the preamble so far from my Sphinx config file:

    \renewcommand\thesection{\hspace*{-0.5em}}
    \renewcommand\thesubsection{\hspace*{-0.5em}}
    \usepackage{bera}
    \usepackage[defaultsans]{lato}
    \usepackage{inconsolata}
    \usepackage{ragged2e}
    \AtBeginDocument{\raggedright}
    \setcounter{tocdepth}{1}
    \pagenumbering{arabic}

Thanks! Brian

  • \renewcommand\thesection{\hspace*{-0.5em}} eeek! really? – David Carlisle Dec 1 '16 at 19:12
  • \let\oldtablefocontents\tableofcontents \renewcommand\tableofcontents{\oldtableofcontents\clearpage} – David Carlisle Dec 1 '16 at 19:13
  • For the \renewcommand\thesection{\hspace*{-0.5em}}, I added that because when I got rid of the section numbers, the section headings were still indented. I don't really know what I'm doing so I googled and found that, but I guess I can google more for a proper left justification. For the \let\oldtablefocontents\tableofcontents \renewcommand\tableofcontents{\oldtableofcontents\clearpage}, I'm not sure if that's a suggested answer? When I add those lines, the TOC disappears altogether. – Brian Madden Dec 1 '16 at 19:37
  • it shouldn't make the toc go, it just adds \clearpage to the end of the definition. presumably your method of removing section numbers was incorrect should just be \setcounter{secnumdepth}{0} – David Carlisle Dec 1 '16 at 19:52
  • @DavidCarlisle I removed my two lines \renewcommand\thesection{\hspace*{-0.5em}} \renewcommand\thesubsection{\hspace*{-0.5em}} and replaced them with \setcounter{secnumdepth}{0} and that works to remove the numbering and they're positioned correctly. But all other forms of \let\oldtablefocontents\tableofcontents \renewcommand\tableofcontents{\oldtableofcontents\clearpage} still give errors. I tried two lines, one line, second line starting with \renewcommand etc., but they all result in the TOC being gone. Thanks for the numbering tip! – Brian Madden Dec 1 '16 at 20:16
1

I believe this is fixed.

My first thought was to just add a blank section in the top of my TOC. That worked, but I felt like it was a hack.

Then I realized that Sphinx has an option for latex where you can set toctree_only=True which means that it will ignore text content from your master doc and only use the TOC from it, and when I set that, it fixes the problem. The first doc starts on the next page. So I'm going to call this 'answered' now.

Thanks everyone!

  • perhaps you could use something like .. only:: not latex in the master doc file. – user4686 Jun 20 '17 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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