Search code examples
jupyter-notebookmarkdownindentationheading

Indent headings in "markdown" cells in Jupyter Notebook after numbering


I am trying to number my headings in Jupyter Notebook. However, this looks quite ugly, as the size of the spaces is of course dependent on the font size.

I am looking for a way to make the text of each of my headings start at the same position, i.e. with the same distance to the left side of the cell.

Here is a code example:

## 1.   heading1
### 1.1   subheading1
### 1.2   subheading2
#### 1.2.1   subsubheading1
## 2.   heading2
### 2.1   subheading1

And what the output looks like: Jupyter Notebook output

Is there a way to do this?

Thank you very much!

Dennis


Solution

  • After a lot of trial and error and googling, I have now come up with a solution myself:

    ## <span style="display: inline-block; width: 50px;">1.</span> heading1
    ### <span style="display: inline-block; width: 50px;">2.1.</span> subheading1
    ### <span style="display: inline-block; width: 50px;">1.2</span> subheading2
    #### <span style="display: inline-block; width: 50px;">1.2.1</span> subsubheading1
    ## <span style="display: inline-block; width: 50px;">2.</span> heading2
    ### <span style="display: inline-block; width: 50px;">2.1</span> subheading1