更正自定义部分 \subsubsubsection 的 PDF 书签层次结构

更正自定义部分 \subsubsubsection 的 PDF 书签层次结构

\subsubsubsection为技术文档定义(我知道这受到了高度批评)。我相信我从中受到了启发替代答案如何在 \subsubsection 下添加带有标题的额外层级当时(我无法使用该包titlesec,但我不记得原因)。

但是,PDF 书签中的层次结构很混乱:subsubsubsection 显示为级别 1 而不是 4,尽管我\@startsection在 的定义中将其指定为级别 4。\subsubsubsection我错误地期望它也能隐式处理 PDF 书签。

我该如何告诉处理 PDF 书签的包(我猜hyperref)是\subsubsubsection级别 4?或者,作为一种次优解决方法,我该如何告诉它\subsubsubsection根本不显示在 PDF 书签中(请记住,设置bookmarksdepth<4不起作用,因为它忽略了它是级别 4)。

在此处输入图片描述

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[pdftex]{hyperref}

\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{4}
\hypersetup{bookmarksdepth=4}

\makeatletter
\newcounter{subsubsubsection}[subsubsection]
\renewcommand{\thesubsubsubsection}{\thesubsubsection.\arabic{subsubsubsection}}
\renewcommand{\theparagraph}{\thesubsubsubsection.\arabic{paragraph}}

\newcommand{\subsubsubsection}{\@startsection{subsubsubsection}{4}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\normalsize\it\bfseries}}
\renewcommand{\paragraph}{\@startsection{paragraph}{5}{\z@}%
                                    {3.25ex \@plus1ex \@minus.2ex}%
                                    {-1em}%
                                    {\normalfont\normalsize\bfseries}}
\renewcommand{\subparagraph}{\@startsection{subparagraph}{6}{\parindent}%
                                       {3.25ex \@plus1ex \@minus .2ex}%
                                       {-1em}%
                                      {\normalfont\normalsize\bfseries}}

\newcommand*{\l@subsubsubsection}{\@dottedtocline{4}{11em}{5em}}  
\renewcommand*{\l@paragraph}{\@dottedtocline{5}{12em}{6em}}
\renewcommand*{\l@subparagraph}{\@dottedtocline{6}{14em}{7em}}

\newcommand{\subsubsubsectionmark}[1]{}
\makeatother

\begin{document}

\tableofcontents

\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\subsubsubsection{SubsubsubSection}


\end{document}

答案1

如果确实需要,bookmark请使用包,depth=3作为选项(即仅限于subsubsection)和(更重要的是!!!):

subsubsubsection您必须指定新内容要挂接到的级别:

\newcommand{\toclevel@subsubsubsection}{4}

这样,您便可告知hyperref(和bookmark)包裹,subsubsubsection柜台位于 4 层。

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[pdftex]{hyperref}
\usepackage[depth=3]{bookmark}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{4}
%\hypersetup{bookmarksdepth=4}



\makeatletter

\newcommand{\toclevel@subsubsubsection}{4}
\newcounter{subsubsubsection}[subsubsection]

\renewcommand{\thesubsubsubsection}{\thesubsubsection.\arabic{subsubsubsection}}


\renewcommand{\theparagraph}{\thesubsubsubsection.\arabic{paragraph}}

\newcommand{\subsubsubsection}{\@startsection{subsubsubsection}{4}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\normalsize\it\bfseries}}
\renewcommand{\paragraph}{\@startsection{paragraph}{5}{\z@}%
                                    {3.25ex \@plus1ex \@minus.2ex}%
                                    {-1em}%
                                    {\normalfont\normalsize\bfseries}}
\renewcommand{\subparagraph}{\@startsection{subparagraph}{6}{\parindent}%
                                       {3.25ex \@plus1ex \@minus .2ex}%
                                       {-1em}%
                                      {\normalfont\normalsize\bfseries}}

\newcommand*{\l@subsubsubsection}{\@dottedtocline{4}{11em}{5em}}  
\renewcommand*{\l@paragraph}{\@dottedtocline{5}{12em}{6em}}
\renewcommand*{\l@subparagraph}{\@dottedtocline{6}{14em}{7em}}

\newcommand{\subsubsubsectionmark}[1]{}
\makeatother

\begin{document}

\tableofcontents

\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\phantomsection
\subsubsubsection{SubsubsubSection}


\end{document}

在此处输入图片描述

答案2

我将此作为后续答案添加给那些(像我一样)有类似设置和问题的人。我创建了一个子小段落(级别 6),它在目录中运行良好,但 PDF 书签将其重置为章节(级别 1)以及其后的每个标题。我使用的是 PDFLaTex。要解决此问题,我只需要将之前答案的 \toclevel 解决方案修改为子小段落 ( \newcommand{\toclevel@subsubparagraph}{6}) 添加到我的\@startsectionMWE 中。图片:左图,问题:子小节放在章节级别;右图,已修复。

\documentclass{book}
\usepackage[bookmarksopen]{hyperref} %,pdfview=Fit %to open bookmark to top of page
\usepackage{bookmark}
\setcounter{secnumdepth}{6} %make sure my subsects all numbered to lowest level
\setcounter{tocdepth}{6} %tell toc to include all numbered subsects as above
\makeatletter
\newcounter{subsubparagraph}[subparagraph]% counter for numbering
\renewcommand{\thesubsubparagraph}%               how to display 
{\thesubparagraph.\@arabic\c@subsubparagraph}%  numbering
\newcommand{\subsubparagraph}{\@startsection
    {subsubparagraph}%
    {6}%
    {0pt}%
    {3.25ex \@plus 1ex \@minus .2ex}% %\baselineskip
    {1.5ex plus 0.2ex}% %\0.5\baselineskip
    {\usefont{OT1}{phv}{c}{sc}\selectfont\fontsize{9}{9}}} %\scshape}}
\newcommand{\toclevel@subsubparagraph}{6} %added to fix pdf bookmark hierarchy
\newcommand*\l@subsubparagraph{\@dottedtocline{6}{10em}{5em}}% for toc
\newcommand{\subsubparagraphmark}[1]{}% for page headers
\makeatother


\begin{document}
     \part{TEST}
     \chapter{chaptest}
     kdkd
     \section{sectest}
     kdkd
     \subsection{subsectest}
     ddk
     \subsubsection{subsubsectest}
     dkdk
     \paragraph{paratest}
     dkdk
     \subparagraph{subpartest}
     dkdk
     \subsubparagraph{subsubpartest}
     dkdkd
     \paragraph{postssptest}
     dkdk
     \subsubsection{postssstest}
     kdkd
     \chapter{postchaptest}
     kdkd
\end{document}

相关内容