11

I am having some issues with the hyperref package. I would like to create a Introduction chapter without a number so I use \chapter*{Introduction} and \addcontentsline{toc}{chapter}{Introduction} because I want it in the table of contents (see example).

But then the link in my PDF viewer gets it wrong and also the automatically created header is no longer correct (see picture). The table of contents shows the right page number (p.1) but the link is also wrong.

What is my mistake here?

\documentclass{scrbook}

\usepackage{hyperref}
\usepackage{blindtext}
\usepackage{glossaries}
  \makeglossaries

\newacronym{eg}{e.g.}{%
for example
}


\begin{document}


\frontmatter

% abstract before the table of contents
\chapter*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}
\blindtext

\tableofcontents

% chapter with acronyms
\cleardoublepage \phantomsection 
\printglossary[type=\acronymtype]
\addcontentsline{toc}{chapter}{Glossary}

\cleardoublepage
\mainmatter


\phantomsection
% \chapter{Introduction} % with this everything is correct but I don't want the number
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}

\blindtext

\pagebreak

\blindtext

% first chapter
\chapter{Chapter1}

\gls{eg}
\blindtext

\pagebreak

\blindtext


\end{document}

screenshot

  • 2
    Looking for addchap? – Johannes_B Jul 29 '14 at 14:08
  • See also One chapter without numeration – Johannes_B Jul 29 '14 at 14:14
  • Seems like I do ;). Thanks a lot. Should \addcontentsline not be used in the KOMA-Scripts or what is the problem here? – Lukas Jul 29 '14 at 15:13
  • You can use \addcontentsline but you have to take care of all the rest yourself. KOMA takes care of it with \addchap so it is reallly useful. – Johannes_B Jul 29 '14 at 15:15
  • It should be noted that \hyperref redefines the \contentsline macro to use 4 args instead of 3. – John Kormylo Jul 29 '14 at 15:36
17

KOMA-Script provides very powerful commands for almost every possible situation. As you noticed, the headers were showing the previous chapter and hyperlinks didn't work properly when using \chapter* along with addcontentsline.

The command \addchap takes care of this. It adds the unnumbered chapter to the table of contents, it sets \markboth accordingly. Additionally it makes sure that hyperlinks are set the right way, it even ensures, that there is the small chapter gap in the list of figures and list of tables.

If, for some reason, you want a different toc-entry, just use the optional command like you are used to.

If you want the unnumbered chapters to be indented as if there were a number, use the documentclass option toc=indentunnumbered. This will have an effect on every chapter that has been set with the documented addxcontentsline (or any higher-level) command. Of course, using \addchap is the way to go.

There is a starred variant as well which does not create a toc-entry and clears the head. This way, the header of the previous chapter is gone.

Commands to be used for unnumbered sections are provided as well, those are \addsec (with its optional argument) and \addsec*.

\documentclass{scrbook}
\usepackage{blindtext}
\usepackage{hyperref}
\newcommand{\filler}{\blindtext[7]}
\begin{document}
\tableofcontents
\addchap{addchap}
\filler
\addchap[ToC entry]{Heading?}
\filler
\chapter{Chapter}
\filler
\addchap*{No ToC Entry, header cleared}
\filler
\end{document}

The standard classes do not provide those commands, but one can easily implement the basic funtionality as is described in How to deal with unnumbered chapters?

2

As pointed out by Johannes_B in the comments using

\addchap{Introduction}

instead of

\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}

solves the problem.

  • i am just writing up an own anwer, with some explanations ;-) – Johannes_B Jul 29 '14 at 15:28
  • Okay thx. I can accept it only in two days anyway ;) – Lukas Jul 29 '14 at 15:35

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.