Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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{}
\addcontentsline{toc}{part}{Academic Career}

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

\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{}
\addcontentsline{toc}{part}{Professional Career}

\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}

screen shot

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
  \addcontentsline{toc}{part}{#1}%
  \hspace{\separatorcolumnwidth}%
  \parbox[t]{\maincolumnwidth}{\strut\sectionstyle{#1}}%
  \par\nobreak\vskip 1ex\@afterheading}% to avoid a pagebreak after the heading

\renewcommand*{\subsection}[1]{%
  \begin{tabular}{@{}p{\hintscolumnwidth}@{\hspace{\separatorcolumnwidth}}p{\maincolumnwidth}@{}}%
    \raggedleft\hintfont{} &{\subsectionstyle{#1}}%
  \end{tabular}%
  \par\nobreak\vskip 0.5ex\@afterheading}% to avoid a pagebreak after the heading
%  \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?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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
  \addcontentsline{toc}{section}{#1}% changed
  \hspace{\separatorcolumnwidth}%
  \parbox[t]{\maincolumnwidth}{\strut\sectionstyle{#1}}%
  \par\nobreak\vskip 1ex\@afterheading}% to avoid a pagebreak after the heading

\renewcommand*{\subsection}[1]{%
  \phantomsection %added
  \addcontentsline{toc}{subsection}{#1}%added
  \begin{tabular}{@{}p{\hintscolumnwidth}@{\hspace{\separatorcolumnwidth}}p{\maincolumnwidth}@{}}%
      \raggedleft\hintfont{} &{\subsectionstyle{#1}}%
  \end{tabular}%
  \par\nobreak\vskip 0.5ex\@afterheading}

\makeatother  
\begin{document}
.......
share|improve this answer
    
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
2  
But how to get a TOC with moderncv? I get the following error if I try: ERROR: Undefined control sequence. --- TeX said --- l.76 \tableofcontents –  user17106 Oct 4 '12 at 21:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.