# How to fix moderncv's ToC generation to get nesting in the PDF ToC

I am preparing a (somewhat lengthly) application using the moderncv class. For this I would like to provide for some additional structure in the PDFs ToC, that is, use something like \addcontentsline{toc}{part}{<entry>} for grouping sections. Also I would like to have the subsections to appear nested below the sections in the PDF ToC.

However, the following fails: All bookmarks appear on the part-level, \subsection does not create a bookmark:

\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{casual}                        % style options are 'casual' (default) and 'classic'
\moderncvcolor{blue}                          % color options 'blue' (default), 'orange', 'green', 'red', 'purple', 'grey' and 'black'
\usepackage[utf8]{inputenc}                   % replace by the encoding you are using
\usepackage[scale=0.75]{geometry}
\firstname{John}
\familyname{Doe}
\begin{document}
\maketitle

\phantomsection{}

\section{Education}
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}  % arguments 3 to 6 can be left empty

\subsection{Master thesis}
\cvitem{title}{\emph{Title}}
\cvitem{supervisors}{Supervisors}
\cvitem{description}{Short thesis abstract}

\subsection{Dissertation}
\cvitem{title}{\emph{Title}}
\cvitem{supervisors}{Supervisors}
\cvitem{description}{Short thesis abstract}

\phantomsection{}

\section{Experience}
\subsection{Vocational}
\cventry{year--year}{Job title}{Employer}{City}{}{General description no longer than 1--2 lines.\newline{}%
Detailed achievements:%
\begin{itemize}%
\item Achievement 1;
\item Achievement 3.
\end{itemize}}
\cventry{year--year}{Job title}{Employer}{City}{}{Description line 1\newline{}Description line 2}
\subsection{Miscellaneous}
\cventry{year--year}{Job title}{Employer}{City}{}{Description}

\section{Languages}
\cvitemwithcomment{Language 1}{Skill level}{Comment}
\cvitemwithcomment{Language 2}{Skill level}{Comment}
\cvitemwithcomment{Language 3}{Skill level}{Comment}

\end{document}


The culprit can be found in the moderncv implementation, more precisely in the definitions of the \section and \subsection commands in moderncvstyleclassic.sty:

\ProvidesPackage{moderncvstyleclassic}[2012/01/25 v0.17 modern curriculum vitae style scheme: classic]
...
\renewcommand*{\section}[1]{%
\vspace*{2.5ex}%
\parbox[t]{\hintscolumnwidth}{\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{\hintscolumnwidth}{0.95ex}}}%
\phantomsection{}% reset the anchor for hyperrefs
\hspace{\separatorcolumnwidth}%
\parbox[t]{\maincolumnwidth}{\strut\sectionstyle{#1}}%

\renewcommand*{\subsection}[1]{%
\begin{tabular}{@{}p{\hintscolumnwidth}@{\hspace{\separatorcolumnwidth}}p{\maincolumnwidth}@{}}%
\raggedleft\hintfont{} &{\subsectionstyle{#1}}%
\end{tabular}%
%  \phantomsection{}% reset the anchor for hyperrefs
%  \addcontentsline{toc}{chapter}{#1}% does not work, the bookmark is placed at the same level as sections (placed themselves at part level to be visible, as hyperref does not allow sections without parents...)


The comment below the \subsection implementation probably explains the problem: sections are placed on part-level, subsections are not placed at all in the ToC because of issues with hyperref. I played a bit around with various \addcontentsline-settings, but without success.

So how can this be fixed?

-

Well I would redefine \section and \subsection so that they use the correct levels (no idea why moderncv doesn't do this):

\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{casual}                        % style options are 'casual' (default) and 'classic'
\moderncvcolor{blue}                          % color options 'blue' (default), 'orange', 'green', 'red', 'purple', 'grey' and 'black'
\usepackage[utf8]{inputenc}                   % replace by the encoding you are using
\usepackage[scale=0.75]{geometry}
\firstname{John}
\familyname{Doe}

\makeatletter
\AtEndPreamble{\hypersetup{bookmarksdepth=2}}% to get sections and subsection in toc

\renewcommand*{\section}[1]{%
\vspace*{2.5ex}%
\parbox[t]{\hintscolumnwidth}{\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{\hintscolumnwidth}{0.95ex}}}%
\phantomsection{}% reset the anchor for hyperrefs
\hspace{\separatorcolumnwidth}%
\parbox[t]{\maincolumnwidth}{\strut\sectionstyle{#1}}%

\renewcommand*{\subsection}[1]{%

This is what I have tried before asking here (and from the comments in the code I conclude that the moderncv author also did try this). The magic line in your solution both of us apparently missed is \hypersetup{bookmarksdepth=2}. Thanks Ulrike! –  Daniel Feb 2 '12 at 16:27
I just updated moderncv to include this. Thanks Ulrike! –  Xavier Feb 13 '12 at 13:32