What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 128 Stack Exchange communities.

I just posted an answer on Stack Overflow where I wanted to have nested numbered lists, something like

1. Dog

1.1. German Shepherd

1.2. Belgian Shepherd

1.2.1. Malinois

1.2.2. Groenendael

1.2.3. Tervuren

2. Cat

2.1. Siberian

2.2. Siamese

As you can see the sublists are not indented, and also "Cat" should be number 2, at the same level as "Dog". I've also tried blockquotes, but still it doesn't work:

  1. Dog

1.1. German Shepherd

1.2. Belgian Shepherd

1.2.1. Malinois

1.2.2. Groenendael

1.2.3. Tervuren

  1. Cat

2.1. Siberian

2.2. Siamese

First part seems to be indented properly, but then numbering goes wrong again, and indentation too.

So, is there a way to write proper markdown for nested number lists?

share|improve this question
    
(As an aside: note that any number might create a numbered list, even if its value does not match the expected value. Like a list such as 3., 2., 4. will still be numbered as 1., 2., 3. (by your browser when it encounters <ol><li>Dog</li><li>Cat</li><li>...</li></ol>). Escaping the dot, like by writing 2\., avoids that Markdown recognizes 2. as an item of a (new or existing) numbered list. Hence, writing 2\. Cat would avoid the new list with 1. Cat as its first item, like in your example above.) –  Arjan Mar 31 '11 at 15:10
    
+1 for using Groenendael :) –  Ivan Ivanić Nov 28 '11 at 11:02

4 Answers 4

up vote 44 down vote accepted

If you're ever stuck on a Markdown question, there's a help button on the right side of the toolbar:

Screenshot of the toolbar

That help page explains how to do the simple case:

Advanced lists: Nesting

To put other Markdown blocks in a list; just indent four spaces for each nesting level

For example (see the markdown for this post):

  1. Dog
    1. German Shepherd
    2. Belgian Shepherd
      1. Malinois
      2. Groenendael
      3. Tervuren
  2. Cat
    1. Siberian
    2. Siamese

I think this is as close as you can get; Markdown doesn't support the "1.1.1" type list you wanted

share|improve this answer
    
Using the rendering above, one could still write "1.2.2" in some related text, to refer to "Groenendaal". –  Arjan Mar 31 '11 at 14:48
  1. List item
    1.1 List item
  2. List item

If I replace space by _ it gives

_1. List item__  
__1.1 List item
_2. List item

The important thing is the double space after the first item. But so far, I got difficulties with the third level. The only solution I found is adding dots...

  1. Dog
    1.1. German Shepherd
    1.2 Belgian Shepherd
    . . 1.2.1. Malinois
    . . 1.2.2. Groenendael
    . . 1.2.3. Tervuren
  2. Cat
    2.1. Siberian
    2.2. Siamese
share|improve this answer
    
ah! I was sure there was a way! thanks! –  MarcoS Mar 31 '11 at 14:24
    
@MarcoS see my edit, look like the solution is not that simple. –  DavRob60 Mar 31 '11 at 14:26
2  
You're not actually making a new nesting level, you're just preventing Markdown from recognizing the indented block as a list (that's why the "third" level doesn't work). I don't think markdown supports nested numbered lists of this sort –  Michael Mrozek Mar 31 '11 at 14:30
    
@Michael Mrozek: oh, that's bad news! so, maybe my question should be retagged as feature-request? –  MarcoS Mar 31 '11 at 14:33
    
@Michael Mrozek you are right, that why I edited this post. your answer is better than mine. –  DavRob60 Mar 31 '11 at 14:34
    
@MarcoS Do you really need the list to say "1.1" instead of just an indented "1."? –  Michael Mrozek Mar 31 '11 at 14:35
    
Actually, @Michael, Markdown kind of supports it, but the CSS is not using double figures for such lists. In the end, the generated HTML is just things like nested <ol>s. One could use CSS counters, but the SE sites don't. –  Arjan Mar 31 '11 at 14:35
    
@Arjan Well, Markdown supports nested lists, but I don't think it supports a way to change their type; the only type you can have is the basic "1." at some indentation level –  Michael Mrozek Mar 31 '11 at 14:36
    
@Marco, please only use this if it's REALLY required. The SE content is not only rendered using every day browsers. This is kind of messing up for other usage, like maybe for screen readers, or when using the data dumps or API. (Leading dots could probably be avoided using &nbsp; but then the same applies: you're mixing formatting with content.) –  Arjan Mar 31 '11 at 14:38
    
(Correct, @Michael, it does not support defining the way lists are rendered or numbered.) –  Arjan Mar 31 '11 at 14:39
    
@Michael Mrozek: I've seen your answer below. That's sort of a workaround. However, I believe that there are cases in which nested lists are useful. For example, when describing steps of an algorithm using natural language. You may want to refer to a sub-step in your answer (or in other answers or comments) to further comment it. –  MarcoS Mar 31 '11 at 14:41
1  
@MarcoS, one can still refer to "1.1" in text elsewhere, when the list has "1." on the first level, and "1." in the 2nd level too. It's just a matter of formatting (which is different from what you want), not a matter of "natural language". In fact, when using "1." on the first level, and "1.1" on the second, then maybe one should refer to that item by writing "1.1.1" rather than the "1.1" you're asking for... –  Arjan Mar 31 '11 at 14:46
1  
@Arjan: yes, you can refer to 1.1 where the first "1" refers to the first level, and the second "1" refers to the second level. However, a nested list as the one showed in Michael Mrozek's answer does not look like the way that people usually expect it. I agree, it's a matter of formatting, but IMHO a traditional nested list is more effective, and, I believe that, although not necessary, it could be nice to have it. –  MarcoS Mar 31 '11 at 14:55

I was inspired by DavRob60's attempt at making a faux nested list. Here's a working version.

Result:

 1. Dog
   1.1. German Shepherd: The German Shepherd Dog (GSD, also known as an Alsatian), (German: Deutscher Schäferhund) is a breed of large-sized dog that originated in Germany.
   1.2. Belgian Shepherd
     1.2.1. Malinois
     1.2.2. Groenendael
     1.2.3. Tervuren
 2. Cat
   2.1. Siberian
   2.2. Siamese

Markdown:

&nbsp;1. Dog  
&nbsp;&nbsp;&nbsp;German Shepherd: The German Shepherd Dog (GSD, also known as an Alsatian), (German: Deutscher Schäferhund) is a breed of large-sized dog that originated in Germany.  
&nbsp;&nbsp;&nbsp;1.2. Belgian Shepherd  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.2.1. Malinois  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.2.2. Groenendael  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.2.3. Tervuren  
&nbsp;2. Cat  
&nbsp;&nbsp;&nbsp;2.1. Siberian  
&nbsp;&nbsp;&nbsp;2.2. Siamese

Note that you have to manually insert line breaks with two trailing spaces on all lines of the list except the last one. You can see this if you highlight the "code."

share|improve this answer
    
And now try with longer items, like 1.1 German Shepherd: The German Shepherd Dog (GSD, also known as an Alsatian), (German: Deutscher Schäferhund) is a breed of large-sized dog that originated in Germany. and long descriptions like that. @MarcoS, I'd say: try to find a way to answer without the need for odd lists! –  Arjan Mar 31 '11 at 17:50
    
I never claimed that this was a good idea. Just pointing out that it is, technically, possible. –  Pops Mar 31 '11 at 17:51
    
(I know, I'm just trying to convince the OP that it's probably not required for a good answer!) –  Arjan Mar 31 '11 at 17:53
1  
Nice, +1 for showing what exactly is happening (and to be avoided)! –  Arjan Mar 31 '11 at 17:57
    
@Popular Demand: nice attempt! –  MarcoS Mar 31 '11 at 19:07
    
@Arjan: I will survive without nested numbered lists, don't worry :) –  MarcoS Mar 31 '11 at 19:08

I needed this kind of numbering the list items, so that's how I solved it:

* 1\. item 
    * 1.1\. item
    * 1.2\. item
* 2\. item 

and the result:

  • 1. item
    • 1.1. item
    • 1.2. item
  • 2. item

I know how it looks but I really needed this kind of numbering and presented solutions ware not what I was looking for.

share|improve this answer

You must log in to answer this question.

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