从 moderncv 中的目录中排除一些文档部分

从 moderncv 中的目录中排除一些文档部分

我想从目录中排除某些部分。

我已经尝试通过操作 tocdeph-counter 来实现这一点。但是,它不起作用,我不明白为什么。

我的代码不会在文档本身中生成可见的目录。我指的是 PDF 阅读器为文件导航显示的目录(此处为 Acrobat 阅读器):

在此处输入图片描述

你有什么想法吗?

请参阅MWE:

\documentclass[11pt,a4paper,sans]{moderncv} 
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\moderncvstyle{casual} 
\moderncvcolor{red}
\firstname{John} 
\familyname{Doe} 

\begin{document}

% Start with a letter which shall be in the ToC as Letter
\phantomsection\addcontentsline{toc}{section}{Letter}
Here a letter will be inserted
\clearpage

% Now the CV starts and shall be in the TOC only with a single entry named CV 
\phantomsection\addcontentsline{toc}{section}{CV}
\addtocontents{toc}{\protect\setcounter{tocdepth}{-1}} % Is not working as the following two sections appear in the ToC!

\section{Something which shall not be in the ToC}
\section{Something which shall not be in the ToC 2}

% From now on an Appendix starts and the sections shall be included in ToC again
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
\section{I shall be visible in the ToC of the PDF}

\end{document}

答案1

试试这个代码。你可以将值更改为bookmarksdepth-1,以隐藏下一个条目的书签,直到你发出\hypersetup{bookmarksdepth=1}

d

\documentclass[11pt,a4paper,sans]{moderncv} 
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\moderncvstyle{casual} 
\moderncvcolor{red}
\firstname{John} 
\familyname{Doe} 

\begin{document}
    
    % Start with a letter which shall be in the ToC as Letter
    \phantomsection\addcontentsline{toc}{section}{Letter}
    Here a letter will be inserted
    \clearpage
    
    % Now the CV starts and shall be in the TOC only with a single entry named CV 
    \phantomsection\addcontentsline{toc}{section}{CV}
            
    \hypersetup{bookmarksdepth=-1}% supress bookmark <<<<<<<<<<
    \section{Something which shall not be in the ToC}
    \section{Something which shall not be in the ToC 2}
    
    \hypersetup{bookmarksdepth=1} %again <<<<<<<<<<
    % From now on an Appendix starts and the sections shall be included in ToC again
    \section{I shall be visible in the ToC of the PDF}
    
\end{document

相关内容