我正在使用titlesec
包创建新的类来在这个层次结构中工作:
第 PART
- 章节
-- 安全前
--- 子安全前
我按照下面的 MWE 所示实现了它们。当我编译文件时,层次LuaLaTeX
结构不被尊重,它们似乎具有相同的级别。右边的图显示了我拥有的,左边显示了我希望拥有的。
另外,目录中的部分不是用小写字母排版的。如何使用我制作的类获得如上所示的层次结构?
\documentclass[12pt,a4paper]{book}
\usepackage[loadonly]{titlesec}
\usepackage{titletoc}
\usepackage{tocloft}
\usepackage{lipsum}
\usepackage{bookmark}
\usepackage{hyperref}
\hypersetup{draft}
\titleclass{\part}[-1]{page}
% Changes in part name appearence
\titleformat{\part}% command
[block]% shape
{\centering\fontsize{30pt}{30pt}\selectfont}% format
{}% label
{0 cm}% sep
{\thispagestyle{empty}}% before-code
[]% after-code
% Changes spaces in between part
\titlespacing{\part}{0 pt}{.4\textheight}{0 cm}
% Add part to toc
\titlecontents{part}[0em]{\Large\bfseries\scshape}{}{}{\hfill\contentspage}[]
% Create prechap class
\titleclass{\prechap}{top}[\part]
\newcounter{prechap}
% Formats prechap entry
\titleformat{\prechap}% command
[block]% shape
{\centering\fontsize{20pt}{20pt}\selectfont}% format
{}% label
{0 cm}% sep
{\uppercase}% before-code
[\thispagestyle{empty}]% after-code
% Changes spaces in between prechap
\titlespacing{\prechap}{0 cm}{1 cm}{1 cm}
% Add prechaps to toc
\titlecontents{prechap}[0em]{\bfseries}{}{}{\hfill\contentspage}[]
% Create presec class
\titleclass{\presec}{straight}[\prechap]
\newcounter{presec}
% Formats presec entry
\titleformat{\presec}% command
[hang]% shape
{\fontsize{14pt}{14pt}\selectfont}% format
{}% label
{0 cm}% sep
{\bfseries}% before-code
[]% after-code
% Changes spaces in between presec
\titlespacing{\presec}{0 cm}{1 cm}{.2 cm}
% Add presecs to toc
\titlecontents{presec}[1em]{\scshape}{}{}{\hfill\contentspage}[]
% Create presubsec class
\titleclass{\presubsec}{straight}[\presec]
\newcounter{presubsec}
% Formats presubsec entry
\titleformat{\presubsec}% command
[hang]% shape
{\fontsize{14pt}{14pt}\selectfont}% format
{}% label
{0 cm}% sep
{\itshape}% before-code
[]% after-code
% Changes spaces in between presubsec
\titlespacing{\presubsec}{0 cm}{1 cm}{.2 cm}
% Add presubsecs to toc
\titlecontents{presubsec}[2em]{\itshape}{}{}{\hfill\normalfont\contentspage}[]
\begin{document}
\tableofcontents
\prechap{Preface}
\lipsum[1]
\prechap{Prelude}
\lipsum[2]
\presec{Section one}
\lipsum[3]
\presubsec{Subsection one}
\lipsum[4]
\presubsec{Subsection two}
\lipsum[5]
\part{Part One}
\lipsum[6]
\prechap{Prechap One}
\lipsum[7]
\presec{Section Two}
\lipsum[8]
\presubsec{Subsection Three}
\lipsum[9]
\end{document}
答案1
当hyperref
将条目添加到书签时,它会从以下形式的命令中获取级别信息\toclevel@<name>
,其中<name>
是文本部分的名称。对于书籍类,这些是
\def\toclevel@part{-1}
\def\toclevel@chapter{0}
\def\toclevel@section{1}
等等。
对于您的新部门类型prechap
,presec
这些presubsec
命令未定义,这会hyperref
在日志中警告您:
Package hyperref Warning: bookmark level for unknown prechap defaults to 0.
Package hyperref Warning: bookmark level for unknown presec defaults to 0.
Package hyperref Warning: bookmark level for unknown presubsec defaults to 0.
由于所有级别都采用新的默认级别 0,因此 PDF 文件中的书签看起来是“扁平”的。解决方案很简单,只需将以下几行添加到文档的序言中,以表明hyperref
您希望新分区对应哪些级别:
\makeatletter
\def\toclevel@prechap{0}
\def\toclevel@presec{1}
\def\toclevel@presubsec{2}
\makeatother
现在书签已按预期嵌套。