Question

I have a very basic setup in Sphinx. The TOC is as follows:

.. toctree::
   :maxdepth: 3

   one
   two

And the files one and two look like this:

one.rst

####
Part
####

*******
Chapter
*******

Section
=======

two.rst:

***************
Another Chapter
***************

Another Section
===============

Both files have the same formatting and I would like to end up with the following structure

Part
|- Chapter
  |- Section
|- Another Chapter
  |- Another Section

However, Sphinx gives me

Part
|- Chapter
  |- Section
Another Chapter
|- Another Section

The reason I'm splitting the files is that they are fairly large and I want to keep them small so I can edit them easily. How can I get the same heading styles (with the same overline/underline characters) but in different files?

Was it helpful?

Solution

I believe what you want is the include directive. For example in 1.rst you will put

####
Part
#### 

*******
Chapter
*******  

Section
=======

.. include:: 2.rst
.. include:: 3.rst
.. include:: 4.rst

This will include 2.rst and however many additional files you want in the current file and continue the current structure layout. Also, change your index.rst to be just the 1.rst.

.. toctree::
   :maxdepth: 3

   1.rst
   part2.rst
   part3.rst

example

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top