1

I would like each chapter title to also be a link to the table of contents, so that I can quickly go back and forth from the TOC to the chapters.

This is my example test.org document:

#+TITLE:  My doc title
#+DATE:   2024-04-03
#+OPTIONS:  toc:2

* Chapter 1

Text...

* Chapter 2

Text...

The generated document (e.g. PDF) will automatically have a table of contents, which successfully links each TOC title to the corresponding chapter.

How can I add a link to each chapter title that sends me back to the table of contents, if this is auto-generated?

1 Answer 1

1

For pdf exports, you need to modify the LaTeX code produced by orgmode. This can be quite complex if you've never used LaTeX before. However, the following seems to work for your request (taken from tex.stackexchange):

#+LATEX_HEADER: \usepackage[explicit]{titlesec} % to change headings
#+TITLE:  My doc title
#+DATE:   2024-04-03
#+OPTIONS:  toc:2

#+begin_export latex
\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries}{\chaptertitlename\ {\fontfamily{cmr}\selectfont\thechapter}}{20pt}{\hyperlink{chap-\thechapter}{\Huge#1}
\addtocontents{toc}{\protect\hypertarget{chap-\thechapter}{}}}
\titleformat{name=\chapter,numberless}
  {\normalfont\huge\bfseries}{}{-20pt}{\Huge#1}
\titleformat{\section}
  {\normalfont\Large\bfseries}{\thesection}{1em}{\hyperlink{sec-\thesection}{#1}
\addtocontents{toc}{\protect\hypertarget{sec-\thesection}{}}}
\titleformat{name=\section,numberless}
  {\normalfont\Large\bfseries}{}{0pt}{#1}
\titleformat{\subsection}
  {\normalfont\large\bfseries}{\thesubsection}{1em}{\hyperlink{subsec-\thesubsection}{#1}
\addtocontents{toc}{\protect\hypertarget{subsec-\thesubsection}{}}}
\titleformat{name=\subsection,numberless}
  {\normalfont\large\bfseries}{\thesubsection}{0pt}{#1}
#+end_export

* Section the first

Quia quo adipisci dolores sed beatae voluptatem nisi dolore. Ex tenetur id
quia id facilis. Ea dolorem explicabo repellat. Nesciunt sit esse dicta
asperiores provident aspernatur quasi eaque. Facere assumenda nostrum
voluptatem qui explicabo ea nobis. Quasi excepturi est architecto impedit
ut.

Labore voluptas impedit ipsum et sunt. Et accusamus ex ea natus voluptas.
Ex et non officiis a. Sapiente perferendis nihil pariatur itaque.

Rem sunt voluptatem esse dolor. Ratione quo sit numquam. Voluptates unde
assumenda odio eum qui soluta quia reiciendis. Cumque inventore
consequuntur est numquam illo. Non id eos quis nesciunt enim. Ab ipsam
possimus impedit explicabo sed.

* Section the second

Hic dolores dolores fugit temporibus deleniti qui ipsa repellendus.
Officiis est consequatur et minima inventore doloribus quas. Mollitia neque
totam et et ut delectus molestias. Rerum necessitatibus veniam non
excepturi. Ut inventore ipsum quis et delectus quibusdam.

Provident rerum quo possimus. Libero consequatur sed mollitia accusamus
facere id. Est fugiat dolor ea commodi in. Numquam est laborum ut quo
beatae sequi repellendus similique. Harum illo magni illum nam ex
voluptatibus. Et quod hic consectetur enim et.

Est dolorem aut eum iusto. Adipisci quasi reprehenderit molestiae
assumenda. Accusantium voluptatum harum neque dolor sunt. Et et minima ut
nihil. Accusantium pariatur suscipit aut magnam sunt quo voluptas. 

Your Answer

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

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