[Tex/LaTex] Add numbered section to toc without using \section

numberingsectioningtable of contents

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

\includepdf[addtotoc={1,subsection,2,title1,1}]{1.pdf}

\includepdf[addtotoc={1,subsection,2,title2,2}]{2.pdf}

\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

Best Answer

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}
\addcontentsline{toc}{section}{\protect\numberline{\thesection}{YourSectionTitle}}


\includepdf[addtotoc={1,subsection,2,title1,1}]{1.pdf}

\includepdf[addtotoc={1,subsection,2,title2,2}]{2.pdf}

\end{document}

enter image description here

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]{%
  \addtocontents{toc}{\protect\contentsline{section}{\protect\numberline{\thesection}#1}{}{}}%
}

\begin{document}
\tableofcontents


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

\includepdf[addtotoc={1,subsection,2,title1,1}]{1.pdf}

\includepdf[addtotoc={1,subsection,2,title2,2}]{2.pdf}

\end{document}
Related Question