The steps below will show you how to insert a table of contents into your Google Doc with page numbers or links as seen in this linked Google Doc. Both the page number and link options are created using the same steps so the process is virtually identical.
Assuming you already have a document written, the next thing that you do, is you go to Insert -> Table of contents.
If you choose the option with links, a table of contents like the one below is automatically created.
The table of contents is made dynamically so there may not need to edit it. It is produced from the formatting in your document by using sections and sub-sections. The best way to look at this formatting is through the document outline. Go to Tools and go to Document outline. As shown in the image below, the outline shows where your Title is and where your headers are.
Document styling
Keep in mind that tables of contents does not pick up Titles. You will have to add your title manually if you want it to show.
Docs, however, does pick up the usage of the header styles.
Video explanation
Indentation
The words “In grass lights” are the first words that have a heading tag and they are also the first words that are in the table of contents. If you look at the table of contents and at the outline, some of the items below this first header are indented. That did not happen by creating a Table of contents and hitting tab. The Table of Contents does this automatically because “Kind Replenish” is styled as a heading 2. If I make a Heading 3, it will indent even further to the right.
Formatting a table of contents manually
You can also format items in the table of contents manually if you want to. However, it’s probably best practice to format it right in your document. If you left-click on the table of contents, and select Change, you can change certain items. You can change the names of the links or remove the link and just keep the text.
Conclusion
The steps above are all you really need to create your table of contents. Once you do it one time, you will be ready to go.