14
\documentclass[12pt,a4paper]{scrartcl}
\usepackage{ngerman}
\usepackage[latin1]{inputenc}
\usepackage{hyperref}
\usepackage{graphicx}
\title{Rechtevergabe Testdokument}
\author{Test1}
\begin{document}
\maketitle
\newpage
\tableofcontents
\newpage
\addcontentsline{toc}{section}{Bereich A}
\addcontentsline{toc}{subsection}{Kapitel I}
\addcontentsline{toc}{subsection}{Kapitel II}
\addcontentsline{toc}{section}{Bereich B}
\end{document}

Gives me no TOC at all (after running pdflatex twice). Moving \addcontentsline to before \tableofcontents and removing \newpage did no change. I intend to obtain a document with TOC only. Thank you.

15

The \addcontentsline commands are written at \shipout. But your page is empty. Removing the \newpage after \tableofcontents should work (it does for me) or put something on the page with the \addcontentsline commands, e.g. \newpage\mbox{}.

|improve this answer|||||
1

If you want a document consisting of only a toc, this snippet (copied from Jevon) will help:

\newcommand\immediateaddcontentsline[3]{%
  \begingroup
  \let\origwrite\write
  \def\write{\immediate\origwrite}%
  \addcontentsline{#1}{#2}{#3}%
  \endgroup
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy