1

I want to include some external documents (PDFs) in the appendix of the document I am writing. I would like to have these included documents listed in my table of contents, but no section heading should be typeset where they appear in the main document.

The setup I constructed with the help of this answer (included below) works fine, except that the links made by hyperref in the ToC all point to the start of the appendix. How can I get links in the ToC that point to the sections?

\documentclass[oneside]{scrbook}
\usepackage{hyperref,scrpage2}

\newcommand*\silentsection[1]{
  \addtocounter{section}{1}
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}
  \sectionmark{#1} % this is to get headers for the section
}

\pagestyle{scrheadings}
\automark{section}
\begin{document}
\tableofcontents
\chapter{main}
\clearpage\section{part}
\clearpage\section{with}
\chapter{some}
\clearpage\section{sections}

\appendix
\chapter{included documents}

\silentsection{one}
Yada.

\cleardoublepage
\silentsection{two}
Yada yada.

\cleardoublepage
\silentsection{three}
Yada yada yada.

\end{document}
  • 1
    Try \phantomsection just before your \silentsection command. – user31729 Aug 21 '14 at 9:13
  • @ChristianHupfer: That works, thanks! If you want to post that as an answer I will accept it. – xebtl Aug 21 '14 at 9:17
2

Manual additions to a Toc (or LoF/LoT etc) via \addcontentsline often require a \phantomsection statement for correct linking, as well as for the bookmarks.

A more elaborate way would apply the \phantomsection command in \silentsection...

\documentclass[oneside]{scrbook}
\usepackage{hyperref,scrpage2}

\newcommand*\silentsection[1]{%
  \addtocounter{section}{1}
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}
  \sectionmark{#1} % this is to get headers for the section
}

\pagestyle{scrheadings}
\automark{section}
\begin{document}
\tableofcontents
\chapter{main}
\clearpage\section{part}
\clearpage\section{with}
\chapter{some}
\clearpage\section{sections}

\appendix
\chapter{included documents}
\phantomsection
\silentsection{one}
Yada.

\cleardoublepage
\phantomsection
\silentsection{two}
Yada yada.

\cleardoublepage
\phantomsection
\silentsection{three}
Yada yada yada.

\end{document}
|improve this answer|||||

Your Answer

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

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