114

I am trying to create a properly nested list using the following code (following Sphinx and docutils docs):

1. X

  a. U
  b. V
  c. W

2. Y
3. Z

I expect this to result in two OLs but I get the following output instead:

<ol class="arabic simple"> 
  <li>X</li> 
</ol> 

<blockquote> 
  <div>
    <ol class="loweralpha simple"> 
      <li>U</li> 
      <li>V</li> 
      <li>W</li> 
    </ol> 
  </div>
</blockquote> 

<ol class="arabic simple" start="2"> 
  <li>Y</li> 
  <li>Z</li> 
</ol> 

What am I doing wrong? Is it not possible to get the following result?

<ol class="arabic simple"> 
  <li>X
    <ol class="loweralpha simple"> 
      <li>U</li> 
      <li>V</li> 
      <li>W</li> 
    </ol> 
  </li>
  <li>Y</li> 
  <li>Z</li> 
</ol> 
muhuk
  • 15,777
  • 9
  • 59
  • 98

2 Answers2

132

Make sure the nested list is indented to the same level as the text of the parent list (or three characters, whichever is greater), like this:

1. X

   a. U
   b. V
   c. W

2. Y
3. Z

Then you'll get the output you expected.

Community
  • 1
  • 1
ddbeck
  • 3,855
  • 2
  • 28
  • 22
  • 5
    It appears that this is not exactly correct. In my case I was using `*` as the list indicator and when I indented my next line the two characters needed to line up with the text of the parent list, my list was treated as a separate list inside of a blockquote. The empirical rule I've found is that the inner list must be *indented at least three characters*. – Akrikos Feb 26 '18 at 22:42
  • @Akrikos Thanks! I updated the answer to include that caveat. – ddbeck Mar 06 '18 at 09:26
  • Indenting the inner list with 3 spaces didn’t work for me when using `*` lists. I think the answer was right the first time. – Pyprohly Oct 30 '21 at 17:33
43

If you want Sphinx to take care of the numbering for you, do this.

#. X
#. Y

   #. u 
   #. v 

#. Z
zsoobhan
  • 1,484
  • 15
  • 18
  • 12
    Just re-highlighting this detail since it still applies: u and v must be indented at least 3 spaces (not 2 spaces), to match the text of the parent level. Otherwise, you'll get "1. Z" instead of "3. Z". – S. Kirby Nov 11 '16 at 21:38
  • 3
    @S.Kirby It also seems that one must indent more, if one uses a list item like `iii.`, which uses more places. It seems text has to be aligned and there seems not to be a specific count of spaces one can use for all cases. – Zelphir Kaltstahl Nov 21 '16 at 17:15
  • 3
    Please note that the extra empty lines are also important here. So you will need 3 spaces for each element of the nested sub list, and above and below an empty line. – flazzarini May 15 '19 at 11:54