8

If I export the following document as a PDF through C-c C-e l p I get a PDF with a table of contents as expected:

* Hello                                                                                                                                      

  This is a test.                                                                                                                            

* World                                                                                                                                      

  Of org mode section numbering.

but if I add num:nil to the options (to disable section numbering) like so:

#+OPTIONS: num:nil                                                                                                                           
* Hello                                                                                                                                      

  This is a test.                                                                                                                            

* World                                                                                                                                      

  Of org mode section numbering.

my table of contents becomes empty.

I'd like to have a table of contents but without all the section numbers. Is there any way to do that? I've tried adding toc:2 as well but that didn't help.


The first one (without the num:nil) looks like this:

enter image description here

and the second one (with the num:nil) looks like this:

enter image description here

(a rather useless table of contents...)

2 Answers 2

4

The num:nil option tells org to export your headings as unnumbered sections, which look like \section* in LaTeX. The normal handling of these sections in LaTeX is to exclude them from the table of contents. To over-ride this, you have to explicitly add them with \addcontentsline, as @Dox has indicated in his answer.

As an alternative, instead of setting the num:nil option, you can use a LaTeX macro to turn of section numbering entirely:

\setcounter{secnumdepth}{0}

If you do this, you only need this one line at the top of your org document, you don't need to add it for every section.

The resulting LaTeX produced by the org-exporter will use normal sections, i.e., \section (without an asterix). These sections show up in your TOC, but will not have numbers.

Using the setcounter macro will only work for LaTeX output, so it's no help if you export to html or other formats.

3
  • Unfortunately clicking on the toc links also doesn't work in this case, they navigate to the first page. Jul 29 at 15:53
  • @user2609980: with the \setcounter case, or the \addcontentsline case? It's working for me with the former.
    – lindes
    13 hours ago
  • Alas, this isn't an ideal solution for me, because I still have to leave out the num:nil in #+OPTIONS, and that means that while the LaTeX/PDF export looks OK, the numbers are still there in the HTML export, which I don't want. It's helpful, though, inasmuch as if I leave HTML aside, I can get what I want with the LaTeX/PDF export using a line near the top of my file with these contents: #+LATEX_HEADER: \setcounter{secnumdepth}{0}
    – lindes
    13 hours ago
2

Of course, that happen also in LaTeX. You could use the option toc:nil to disable the table of contents. Otherwise you can trick it using the LaTeX code which forces the sections to appear in the table of contents

* Hello @@latex: \addcontentsline{toc}{section}{Hello}@@
  This is a test 
* World @@latex: \addcontentsline{toc}{section}{World}@@
  Of =org-mode= section numbering

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.