28

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.

Johann Bzh
  • 834
  • 3
  • 10
  • 25

4 Answers4

19

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

Saravanabalagi Ramachandran
  • 8,551
  • 11
  • 53
  • 102
  • 2
    Thank you. But Leo have the requested behavior without any extension. They must be something simpler. – Johann Bzh Jun 20 '18 at 14:55
  • I agree with @johann, the query is asking a simple question and this solution is extremely heavyweight and lacks specificity to the question. – Andrew Medlin Nov 08 '18 at 00:25
  • 1
    -1 for "I don't think you're trying to just number your headings." Please don't change the scope. People may indeed just want to number the headings. – isarandi May 10 '19 at 13:40
  • 3
    Thanks for the comment; I've updated my answer. I agree that this is not the answer to the question, however, this may be useful for those who come here looking for more. – Saravanabalagi Ramachandran Jan 08 '20 at 11:08
  • This is very helpful! Also works on JupyterLab with extension: https://github.com/jupyterlab/jupyterlab-toc – egor.ananyev Feb 10 '20 at 03:26
  • is there an equivalent for vscode? – Marc Feb 12 '22 at 16:10
  • Not sure, but this worked for me I was trying to get rid of those pesky numbers in my headings. Just had to disable Toc2. – Adam D. Mar 26 '23 at 00:04
4

I found a solution to this problem in Jupyter Lab (mine is 3.3.4) without any extension. If you have Anaconda, then both classic Jupyter and Jupyter lab comes preinstalled.

Go to Settings -> Advanced Settings Editor. In the left pane, select table of contents and enable the h1 numbering as follows.

enter image description here

Now open any Jupyter-notebook (.ipynb) and select The third icon on the very left panel enter image description here. This will bring down the table of contents. Now click on the icon with numbering above the table of contents enter image description here.

Now you will see that all the headings and subheadings are numbered everywhere.

enter image description here

You can use the table of contents to navigate in the Jupyter notebook.

Prakhar Sharma
  • 543
  • 9
  • 19
2

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/

Machavity
  • 30,841
  • 27
  • 92
  • 100
Oliver Prislan
  • 320
  • 4
  • 12
1

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

Input cell with markdown: Input cell with markdown

notebook display: notebook display

tested on notebook version 5.4.0

JustBaron
  • 2,319
  • 7
  • 25
  • 37
Xiaodong
  • 27
  • 2