Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numbered headers in jupyter notebooks

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.

like image 382
Johann Bzh Avatar asked Mar 09 '18 08:03

Johann Bzh


People also ask

How do I make a numbered list in Jupyter notebook?

Numbered lists: Start with 1. followed by a space, then it starts numbering for you. Start each line with some number and a period, then a space. Tab to indent to get subnumbering.

How do you show headers in Jupyter notebook?

Use the number sign (#) followed by a blank space for notebook titles and section headings: # for titles. ## for major headings. ### for subheadings.

Is there a level 4 heading in Jupyter notebook?

Break down your notebook into smaller parts and use Heading levels 2, 3, 4, and so on for the hierarchy of topics and sub-topics. A notebook should ideally have just one Heading level 1, under which multiple Heading levels of 2, 3, 4, and so on are nested.


2 Answers

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

enter image description here

  1. Refresh and you now have nicely organized notebook

enter image description here

like image 105
Saravanabalagi Ramachandran Avatar answered Oct 19 '22 00:10

Saravanabalagi Ramachandran


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/

like image 35
Oliver Prislan Avatar answered Oct 19 '22 02:10

Oliver Prislan