3

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?

3
  • 4
    You are aware there is no chapter support in article? there's no \chatpter command and thus of course no support for formatting chapters in the toc. Please use a document class that supports chapters.
    – daleif
    Jul 8, 2015 at 5:51
  • ... for example, report or book classes.
    – Sigur
    Jul 8, 2015 at 6:18
  • Or, as you load titlesec, you can create \chapter as a new sectional level for the article class, between part and \section.
    – Bernard
    Jul 8, 2015 at 8:51

2 Answers 2

5

The standard article class does not support the use of \chapters. Separation of \sections is typically achieved by using \parts:

enter image description here

\documentclass{article}
\usepackage{titlesec,hyperref}

\begin{document}

\tableofcontents

\newpage

\phantomsection
\addcontentsline{toc}{part}{Chapter 1}

\section{First Section}

\end{document}
0
1

Here is a solution

\documentclass{article}
\usepackage{hyperref}
\usepackage{titlesec}
 \makeatletter
 \let\l@chapter\l@section
 \let\l@section\l@subsection
 \let\l@subsection\l@subsubsection
 \makeatother
\begin{document}

\tableofcontents

\newpage

\phantomsection
\addcontentsline{toc}{chapter}{Chapter 1}

\section{First Section}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .