# PDF Bookmark chapter-hierarchy not showing correctly

I've have created a LaTeX document to merge several pdf files and to create a ToC of it for easy navigation.

However I have an annoying issue with the pdf Bookmark hierarchy not showing correctly for chapters when opening the pdf file.

For some reason, the next chapter ends up as a subsection under the last section of the previous chapter as shown on the images below: Below is a minimal working example (excl. pdf files):

\documentclass[a4paper,11pt,fleqn,fleqn,twoside,openany]{memoir}
\usepackage[utf8]{inputenc}

\usepackage{pdfpages}

% ¤¤ Table of content ¤¤ %
\setsecnumdepth{subsection}
\maxsecnumdepth{subsection}
\settocdepth{subsection}
\setlength\cftsubsectionnumwidth{3.5em}

% ¤¤ Visual references ¤¤ %
citecolor = black,
urlcolor = black
}

\begin{document}

\tableofcontents*

%%%%%%%%%%%%%% KAPITEL 1 %%%%%%%%%%%%%%
\setcounter{chapter}{1}
\setcounter{section}{2}
\addcontentsline{toc}{chapter}{Kapitel 1 \hspace{1pt} Beton - verdens vigtigste byggemateriale}
1,section,1,Arkitektur,1.3,
2,subsection,2,Beton i arkitekturen,1.3.1,
36,subsection,2,Produktionsmæssige præmisser,1.3.3,
40,subsection,2,Ældning og patinering,1.3.4,
43,subsection,2,Litteratur,1.3.5}]
{Filer/kap_1-3_arkitektur.pdf}

%%%%%%%%%%%%%% KAPITEL 2 %%%%%%%%%%%%%%
\setcounter{chapter}{2}
\setcounter{section}{0}
\addcontentsline{toc}{chapter}{Kapitel 2 \hspace{1pt} Krav til beton}
2,section,1,Hovedkrav,2.1,
5,section,1,Krav til beton i tørt miljø,2.2,
6,section,1,Eksponerings- og miljøklasser,2.3,
7,section,1,Levetid,2.4,
9,section,1,Kravformuleringer,2.5,
9,subsection,2,Velkendt teknologi,2.5.1,
11,subsection,2,Foreskreven beton eller designet beton,2.5.2,
11,section,1,Detailkrav,2.6,
11,subsection,2,Kravdokumenter,2.6.1,
16,section,1,Funktionskrav,2.7,
17,section,1,Litteratur liste,2.8,
{Filer/kap_2-0_krav_til_beton.pdf}

\end{document}


This happens for every new chapter and so the pdf bookmark hierarchy just gets deeper and deeper, which kinda makes the bookmark hierarchy useless...

It kinda seems to be related to ToC Depth command \settocdepth{subsection}.

If I comment or remove it, the Bookmark Hierarchy show fine, but doesn't go deeper than section as shown on image below:

Also tried replacing \settocdepth{subsection} with \setcounter{tocdepth}{3} but it yields same result/issue.

• Could you try to offer a more minimal example? I don't think hypersetup plays any role in your problem, or that you need 9 sections for your problem to show up: write an example as minimal as posible, to make it easier to understand (both for you and the people willing to help you). Sep 18, 2017 at 16:39
• I choose just to include two of my chapters from the big document as an example for illustration. I could of course include fewer section, if that is better, but thought the code matched the screenshot better with all the sections as they only fill 1 line each. Sep 18, 2017 at 20:31

Don't use \setcounter but \refstepcounter{chapter}:
\refstepcounter{chapter}