1

I have the following format:

\part{X}
\section{foo}
\section{bar}
\subsection{foobar}

I don't want any chapters. Unfortunately, hyperref is throwing warnings over this. How can I either make hyperref ignore the missing chapters or include them in a way so they are not showing up in the PDF?

MWE:

\documentclass[12pt,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}

\title{MWE}
\author{Andrew Yang}
\date{\today}

\begin{document}

\maketitle

\part{Test}
\section{Introduction}

\end{document}
Tiuri
  • 7,749
leonheess
  • 350

2 Answers2

1

The complete warning is:

Package hyperref Warning: Difference (2) between bookmark levels is greater
(hyperref) than one, level fixed on input line 14.

When hyperref creates the bookmarks, it orders them hierarchically to display them in a tree-structure. In the default scheme, \part creates a bookmark at level -1, \chapter at level 0, \section at level 1, and so on. The warning tells you that by not having any \chapter, there is a gap in the bookmark levels.

I borrowed from this answer to redefine the levels such that \section creates a bookmark at level 0 (the level of \chapter), and so on. With that, the warning disappears.

MWE:

\documentclass[12pt,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}

\title{MWE}
\author{Andrew Yang}
\date{\today}

\makeatletter
\renewcommand{\toclevel@section}{0}
\renewcommand{\toclevel@subsection}{1}
\makeatother

\begin{document}

\maketitle

\part{Test}
\section{Introduction}

\end{document}
Tiuri
  • 7,749
0

I don't understand why you are using the report class within which chapters are an integral element. Is there any reason not to use the article class?

As a different approach you could use the memoir class with the article option

\documentclass[article, ...]{memoir}
\begin{document}
\part{A part}
\chapter{Typeset as a section}
\section{Typeset as a subsection}
...
\end{document}

which makes a chapter appear as a section, a section appear as a subsection, and so on. If later on you decide that you do want \chapter to be typeset as a chapter, just delete the article option.

Note: In the report class section number are preceeded by the chapter number; if you don't use chapters in the class then you will probably want to change the section numbering. Just another complication.

Peter Wilson
  • 28,066