How to include a local table of contents into Sphinx doc?

PythonPython SphinxRestructuredtextTableofcontents

Python Problem Overview


How to include a local table of contents into Sphinx doc?

I tried

.. toc:: 

But that doesn't seem to have any effect: nothing is inserted in the document.

Basically I need links to the sections in the current page to be placed at a certain location of each page.

Is this possible?

Python Solutions


Solution 1 - Python

I'm not 100% sure this is what you're looking for, but the .. contents:: directive may help. By default, it'll give you the headings for the whole page, wherever you put the directive. With :local: specified, it will generate a local TOC for the headings below where you put the directive (handy for sub-section tocs).

.. contents:: Table of Contents
    :depth: 3

More details here: http://docutils.sourceforge.net/docs/ref/rst/directives.html#table-of-contents

Solution 2 - Python

I had more luck with:

.. contents:: Table of Contents
   :depth: 1
   :local:
   :backlinks: none

The backlinks gets rid of the annoying links back from the headings to the toc.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEdy BourneView Question on Stackoverflow
Solution 1 - PythonmorricView Answer on Stackoverflow
Solution 2 - PythonisparksView Answer on Stackoverflow