Monday, October 29, 2012

Insert a Table of Contents in a Google Doc with LibreOffice

In another post, I told of my troubles with LibreOffice and Outline Numbering and how it stopped me from setting a table of contents in a file I downloaded from Google Drive.  Finally, I successfully inserted a table of contents into a Google Docs document using LibreOffice with the correct page numbering. It's not hard but somewhat tedious. There are basically 4 things you need to do.

Step 1: Setup the document.

Download the Google Doc document as an LibreOffice/OpenOffice .ODT file. It will likely download it into a temp file. Normally, you can't edit that. So save the file somewhere else to allow for editing. Move the cursor top of the page.
Insert a manual break and change the type to Page Break. Then set the Style to be Default. Now change page number to 1.
Again, move the cursor up to top of document.  Press F11 to bring up the Styles and Formatting window. Select the Page Styles icon from the top row and double click on the First Page style.
Just to check, move the cursors between the top of the document and into the other section and back up and check the name of the section on the status bar at the bottom of the window. The top one should say First Page while the one below it should say Default.
For a better way to do it, scroll down to the comments sections and check out Julian's way of doing Step 2 onward.

Step 2: Correct Outline Numbering styles
Click on Tools - >  Outline Numbering to bring up the Outline Numbering window.
Select Level 1 from the list on the left. In the Paragraph Styles section, choose Heading 1.
Now select Level 2 from the list. Under Paragraph Styles, select Heading 2.
Repeat the process for all levels that have an empty Paragraph Sytle.

Step 3: Re-apply all headings sytles
In the Styles and Formatting window, select the Paragraph Styles icon from the top row. Select the heading line text and apply the heading style by double-clicking Heading 1 or Heading 2 or the appropriate heading in the Styles and Formatting window. Repeat for all heading lines text.

Step 4: Insert the Table Of Contents
Move the cursor back to the top of the document. Press Enter a few time to a line or two from the top. Click on Insert and select Index and Tables. From the menu select
Index and Tables. A window will open and the default choice it Table of Contents. Click on OK to insert the table of contents.

Seems like a lot of work but this will set up the document correctly and in a sane manner. If you are not used to LibreOffice, you will find formatting from the Styles and Formatting window some getting used to. But it is part of the style of working with LibreOffice. For example, if you want to change the format of the text in the table of contents, you need to modify the paragraph style for Contents Heading, Contents 1 or Contents 2.
If you think this is hard work, the equivalent work in MS Word is harder or just as involved for Step 1, especially if you want to add a cover page. Also in MS Word, once you set it up in a similar way, you still have to insert the page number in a certain way or else you get page number from the first page of the document and not the first page of the section. I've done that enough times to appreciate the process.
I don't try to add the cover page in LibreOffice because of potential formatting issues. It's better if I do a cover in Inkscape, export it to PDF and combine it with the document PDF in the final step.


  1. I found a simpler way...
    Download .odt
    Insert ToC (may appear as just Table of Contents)
    Tab: Index/Table
    Select: Create from Additional Styles (clear others)
    click ... by Additional Styles
    click Heading 1
    click right arrow to set indent in Toc
    repeat for each level of headings
    Update ToC (click right in it)

    1. Anonymous5:25 PM

      This method does not create correct bookmark indent when Export as PDF.

  2. Thanks Julian. I tried it out and it works as advertised. Your instructions would replace my Step 2 onwards. Step 1 is just to ensure the page numbers appear correctly in the TOC by making the page after the TOC to be page 1.
    Well done.

  3. Anonymous4:33 PM

    Thanks guys! Problem still exists in LibreOffice 4.2.*. Solution worked for me (2014/06/17), and pdf seemed to export fine too.


Recently Popular