如何修复 moderncv 的 ToC 生成以在 PDF ToC 中进行嵌套

如何修复 moderncv 的 ToC 生成以在 PDF ToC 中进行嵌套

我正在准备一个(有点冗长的)应用程序,使用现代简历类。为此,我想在 PDF 目录中提供一些额外的结构,即使用类似于\addcontentsline{toc}{part}{<entry>}对部分进行分组的东西。此外,我还希望子部分嵌套在 PDF 目录中的部分下方。

但是,以下操作失败:全部书签出现在部分级别,\subsection不会创建书签:

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

截屏

罪魁祸首可以在 moderncv 实现中找到,更准确地说是在\section\subsection命令的定义中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...)

实现下方的评论\subsection可能解释了这个问题:部分被放置在部分级别,由于 hyperref 的问题,子部分根本没有放置在目录中。我尝试了各种\addcontentsline设置,但没有成功。

那么如何解决这个问题呢?

答案1

我会重新定义\section\subsection以便他们使用正确的级别(不知道为什么 moderncv 不这样做):

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

相关内容