I'm trying to add a new chapter to both the bookmarks in the PDF as well as the table of contents, without having the chapter appear on the page outside of the TOC. When I try this using \addcontentsline{toc}{chapter}{Chapter Title Here}
, it gets an error and won't compile. Here's the code that errors:
\documentclass{article}
\usepackage{hyperref}
\usepackage{titlesec}
\begin{document}
\tableofcontents
\newpage
\phantomsection
\addcontentsline{toc}{chapter}{Chapter 1}
\section{First Section}
\end{document}
Interestingly, when I change chapter to section and section to subsection, everything works as I want, except that I want these to be at the chapter and section levels instead:
\documentclass{article}
\usepackage{hyperref}
\usepackage{titlesec}
\begin{document}
\tableofcontents
\newpage
\phantomsection
\addcontentsline{toc}{section}{Chapter 1}
\subsection{First Section}
\end{document}
Is there a way to fix the top example so that it works like the second example but with the desired levels?
Best Answer
The standard
article
class does not support the use of\chapter
s. Separation of\section
s is typically achieved by using\part
s: