2

I'm trying to create a table of contents in lyx, so I used \addcontentsline{toc}{chapter}{Topic} right after each heading, in ERT. However, this happens:
problematic image

I have two issues: The first is that I would like to replace the text "Contents" with "Table of Contents". I would also like to add a gap between each heading and the page number, as well as a line break between successive headings. All of them are glued together in one big mess. How do I address this?

Ivan
  • 4,368

1 Answers1

2

Do not do that. To make a table of contents is just InsertList/TOCTable of Contents and then simply write the chapters after the inserted box. You can the preview of the TOC in Navigate menu or clicking in Table of Contents gray box.

To change the title of the TOC, see How to change the title of ToC? and modify accordingly the LaTeX preamble in DocumentSetings....

Use \addcontentsline only to manually "add" to the automatic contents something that usually should not be in the TOC, like unnumbered headers with the ending start in the left dropdown menu.

But before of thinking in manual entanglements, also in DocumentSetings... go to Numbering & TOC to set which numbered headers must be numbered (worth the redundancy) and in the TOC by default.

Fran
  • 80,769
  • How do I set headers? All my headings are in a custom style compared to the rest of the document: bold and underlined. Is there some way I can set all of them as headers, thereby automatically inserting them into the TOC? Also, does that mean I have to delete all the ERT I used for addcontentstoline? – AntPalmer Mar 21 '21 at 05:36
  • @AntPalmer Just type the header and select in the left dropdown menu "Chapter", "Section" or so ... No need of ERT boxes. The style of the headers is another story and the way of change the default depend on the class you are using (it can be done by own class commands or with the titlesec package) but my advice is try first the default headers style (without underlining). – Fran Mar 21 '21 at 09:14
  • I did that, and the sections show up in the toc section, but when I export to PDF, this happens: https://imgur.com/a/khILNJi – AntPalmer Mar 21 '21 at 09:59
  • Edit: Never mind, I understood the problem. I had set the headings as unnumbered sections instead of numbered sections – AntPalmer Mar 21 '21 at 10:59
  • Edit 2: It works, but the text is misaligned. For example, the heading is one line of the TOC, but the page number is on the next line. How do I fix that? – AntPalmer Mar 21 '21 at 11:17
  • Edit 3: I got that issue resolved as well. I had to use a line break at the end of each heading so that body text doesn't accidentally become a heading. Anyways, I can safely remove the line breaks now and it works! – AntPalmer Mar 21 '21 at 11:53
  • Thanks a lot for all the help! – AntPalmer Mar 21 '21 at 11:53
  • 1
    @AntPalmer Can you please accept this answer if it answered your question? It would be nice to get it out of the non-accepted-answer queue. Please also consider giving a +1 if you found the answer useful. – scottkosty Dec 11 '21 at 02:37