Numbered headers in jupyter notebooks

2020-07-01 05:57发布

问题:

I'd like to change the way Jupyter displays the so called heading cells. By default, heading levels are only differentiated through a different font size. I'd like jupyter to display hierarchical numbered titles so that :

# Heading 1

# Heading 2

## Sub Heading

# Heading 3

would display something like :

1 Heading 1
2 Heading 2
2.1 Sub Heading
3 Heading 3

I don't get this with Jupyter 4.2.3.

回答1:

If it's only about getting the headings and numbering, then use markdown syntax, you wouldn't need any extensions (as suggested in Xiaodong's answer).

If you're trying to not only number your headings, but also looking for something that actually organizes and help you navigate around the notebook in addition to just numbering, then you will need ToC2 extension.

  1. Install nbextensions and it's control panel

    conda install -c conda-forge jupyter_contrib_nbextensions jupyter_nbextensions_configurator
    
  2. Enable ToC2

  1. Refresh and you now have nicely organized notebook



回答2:

What you like is actually the default display style of jupyter notebook.

Input cell with markdown:

notebook display:

tested on notebook version 5.4.0



回答3:

There is on tiny step I may overlooked:

conda> jupyter contrib nbextension install --user      # to activate js

perfectly explained in: http://jupyter-contrib-nbextensions.readthedocs.io/en/latest/