How do you make lettered lists using markdown?

2019-03-08 16:52发布

问题:

Markdown allows ordered lists using numbers. How can I instead get an ordered list using letters? i.e.

A. the letter A
B. the letter B
C. etc

instead of

1. the number 1
2. the number 2
3. etc.

回答1:

It doesn't appear that standard Markdown has this capability. You can:

  1. Use CSS, by putting this somewhere in your markdown document (note, this will effect all ordered lists in the document)

    <style type="text/css">
        ol { list-style-type: upper-alpha; }
    </style>
    
  2. Use an extended version of markdown. Pandoc markdown has a fancy_lists extension that will allow you to mark lists with letters and roman numerals.

    http://johnmacfarlane.net/pandoc/demo/example9/pandocs-markdown.html



回答2:

Markdown itself cannot do that, but since you can put HTML in it, this provides a pretty simple way to do it:

<ol type="a">
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ol>

Some derivations on some platforms might interpret only a very strict subset of HTML. For example, StackOverflow doesn't support the type attribute. But Wikipedia's MediaWiki Markdown does, and the GitHub Wiki Markdown does too.



回答3:

At least for recent versions of Pandoc (I'm using version 1.13.1), it looks like you can use some of the fancy_list syntax without having to enable the extension, e.g.:

I.  One                                                                                                                                                                                        
    A.  two                                                                                                                                                                                    
        1. three                                                                                                                                                                               
        2. four                                                                                                                                                                                
            i.  five                                                                                                                                                                           
            ii.  six                                                                                                                                                                           
                - seven                                                                                                                                                                        
                    * eight                                                                                                                                                                    
II.  Nine

To compile this into a PDF you can then run:

pandoc input.md -o output.pdf

NOTE: For this to work, you have to make sure you add an extra space after any letters or roman numerals: instead of the usual one space between a bullet and the text, use two instead. (see pandoc docs)



回答4:

Late to the party, but this might help other people looking for an R Markdown solution.

In R Markdown it's straight forward. The following minimal example lists.rmd shows different types:

---
title: "Lists"
output: pdf_document
---

A list with bullet points:

- Something
- Something else

A numeric list:

1. Something
1. Something else

A list using small letters:

a) Something
a) Something else

A list using capital letters:

A) Something
A) Something else

This knits to:



标签: markdown