# using \include for unnumberred chapters and sections ->tableofcontent mess?

I want to have a document with the following preconditions:

• sections in separate files -> \include{}

• chapters and sections are unnumbered -> using \addchap{} and \addsec{}

• chapter headings should only appear in tableofcontents

For the not appearing chapter headings I adopted and modified a brilliant solution by user egreg:

Removing any one of the preconditions gives a sensible table of contents. All three make a mess. It's like a reverse borromean ring. My main document looks something like this:

\documentclass[english, a4paper, 12pt]{scrbook}
\usepackage[english]{babel}
\usepackage{blindtext}

\begin{document}
\makeatletter
\newcommand\nochap[1]{%
\begingroup
\endgroup
}
\makeatother

\tableofcontents

\nochap{That'n'those}
\include{alottatext}
\include{alottamoretext}
\end{document}


with alottatext looking like:

\addsec{alottatext}
\blindtext


alottatext

That'n'Those

alottamoretext

whereas the expected result would've been:

That'n'Those

alottatext

alottamoretext

So it always moves the Chapter one position down. hyperref would still work right.

I know it's quite a puzzle but maybe anyone can help getting the order right.

• @Welcome to TeX.SX! Works like expected, in the order you desired! It would be nice that we should not have to generate the included files as well, i.e. post full documents, not fragments we've to glue together – user31729 May 26 '16 at 17:06
• But alottatext and the main document ARE seperate documents, as I wrote them down. That is the whole point! If I have them in one document it works for me as well – Igel_in_aspic May 26 '16 at 17:40
• I have used them as separate documents as well. I don't know what you're complaining about – user31729 May 26 '16 at 17:58
• @Christian Hupfer It seems that the OP uses an older KOMA-Script version (3.17 or older). Then I can reproduce the issue. With an uptodate KOMA-Script version the order in TOC is ok but I get an extra page with the chapter heading. – esdd May 26 '16 at 20:20

If you are using KOMA-Script version 3.17 or older you have to replace \include{...} by \clearpage\input{...}. If you do not want that the content of the loaded file starts on a new page then use only \input{...}.

With KOMA-Script version 3.18 or newer there is no problem with the order of the TOC entries. But the code that removes the chapter heading does not work anymore. So you have to change the defintion of \nochap to

\newcommand\nochap[1]{%
\cleardoublepage
}


Note that this code also works with older KOMA-Script versions.

\begin{filecontents*}{alottatext.tex}
\blindtext
\end{filecontents*}

\begin{filecontents*}{alottamoretext.tex}
\blindtext
\end{filecontents*}

\documentclass[english, a4paper, 12pt]{scrbook}
\usepackage[english]{babel}
\usepackage{blindtext}

\newcommand\nochap[1]{%
\cleardoublepage
}

\begin{document}
\tableofcontents
\nochap{That'n'those}

\clearpage\input{alottatext}

\clearpage\input{alottamoretext}
\end{document}


To ensure that it works with hyperref use \phantomsection in the definition of \nochap:

\newcommand\nochap[1]{%
\cleardoublepage
\ifundefinedorrelax{phantomsection}{}{\phantomsection}%
}


Example (without \clearpage before \input):

\begin{filecontents*}{alottatext.tex}
\Blindtext[10]
\end{filecontents*}

\begin{filecontents*}{alottamoretext.tex}
\Blindtext[10]
\end{filecontents*}

\documentclass[english, a4paper, 12pt]{scrbook}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{hyperref}

\newcommand\nochap[1]{%
\cleardoublepage
\ifundefinedorrelax{phantomsection}{}{\phantomsection}%
}

\begin{document}
\tableofcontents
\nochap{That'n'those}

\input{alottatext}
\input{alottamoretext}
\end{document}

• You omitted the \include precondition. Without that my example works as well. Thanks still... seems like a neat solution for \nochap – Igel_in_aspic May 26 '16 at 17:31
• See my updated answer. Replace \include{..} by \cleardoublpage\input{...}. – esdd May 26 '16 at 17:47
• \input does the trick! actually replacing \input is the only thing i have to do. I knew it was easy as that. \hyperref doesn't work anymore now but i consider that a minor issue. Thanks a lot – Igel_in_aspic May 26 '16 at 18:10
• It works with hyperref if you use \phantomsection (see my updated answer). But take care of the page header. Maybe you have to use \markboth{#1}{}, but I do not know the requirements. – esdd May 26 '16 at 20:08