I found how to create a table of contents: Python: Create a "Table Of Contents" with python-docx/lxml But, when I try to create ToC element by this code: