# Add numbered section to toc without using \section

I'd like to have a new section in line with the usual numbering, without it showing in the text. I include multiple PDF files using the \includepdf command. Each of them is a subsection which I'd like to subordinate under the section. However, I can't just use \section because that makes a new headline in the document and I do not want this, especially because I have no other text except the files and an empty site with just the headline on it looks silly.

Example:

\documentclass{scartcl}
\usepackage{pdfpages}

\begin{document}
\tableofcontents

\end{document}


I want it to look like

1.Section
1.1 title1
1.2 title2


without having a nearly empty page because \section makes a new headline

• Welcome to the site! You can use the addcontentsline command - there are lots of instances of its use on our site :) – cmhughes Jul 3 '14 at 16:57
• unfortunately, \addcontentsline does not produce a number in front of the entry – Martin Jul 3 '14 at 17:04
• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Adam Liter Jul 3 '14 at 17:11
• I added an example. Hopefully, it's more clear what I want now – Martin Jul 3 '14 at 17:39

I do not know whether this is what is requested, but it is quite easy to add a non-existing section (or anything) to the TOC and use a section number in front of it.

User cmhughes already pointed to \addcontentsline

Please change the title and the corresponding section number.

\documentclass{article}
\usepackage{pdfpages}

\begin{document}
\tableofcontents

\setcounter{section}{1}

\end{document}


Updated with some support for hyperref such that no stupid link is generated

hyperref adds a 4th {} argument to \contentsline which is meant for the hyperanchor. If empty, no anchor and link is generated. If hyperref is not loaded, the empty 4th argument with {} does not harm any way, it can remain in the .toc file.

\documentclass{article}
\usepackage{pdfpages}

\usepackage{hyperref}

\newcommand{\phantomsectiontotoc}[1]{%
}

\begin{document}
\tableofcontents

\setcounter{section}{1}
\phantomsectiontotoc{YourSectionTitle}

\end{document}

• that's exactly what I was looking for, thank you – Martin Jul 3 '14 at 18:03
• @Martin: Alright, please test and give feedback ;-) – user31729 Jul 3 '14 at 18:05
• How does hyperref react to adding contentlines manually? – 1010011010 Jul 3 '14 at 18:07
• @1010011010: Good question: Normal sections behave well, but a click on YourSectionTitle will lead to the TOC, at least that is what I guess -- I just checked. It is exactly as I wrote. I suppose, a manual \hypertarget can cure this problem – user31729 Jul 3 '14 at 18:09
• A special command in conjunction with \phantomsection should work. I will check later on – user31729 Jul 3 '14 at 18:27

Only an addendum to Christian's first example:

To have a solution with correct automatic bookmark for the \addcontentsline with hyperref you need to use \refstepcounter to increase the section counter. And you should insert \clearpage before adding the section entry to the table of contents, because otherwise it wouldn't refer to the page of the first included PDF page but to the page before:

\documentclass{article}
\usepackage{pdfpages}
\usepackage{hyperref}

\begin{document}
\tableofcontents

\clearpage% to have the section on the correct page
%\stepcounter{section}{0}% If you need section number n instead of the next one, set section number n-1 here, because you still need:
\refstepcounter{section}


Note, this solutions works independent from using hyperref.
• @ChristianHupfer One could argue that your solution misses the page number for the fake section in the ToC. If this is requested, everything is fine … ;-) And one could ague that a ToC should contain only headings that are shown in the document. So one should do whatever he/she likes best. – Schweinebacke Apr 18 '17 at 19:01