这是我的 MWE:
\documentclass[11pt,a4paper,oneside]{memoir}
\pagestyle{plain}
\usepackage[explicit]{titlesec}
\usepackage{fontspec}
\usepackage{xltxtra}
\usepackage{polyglossia}
\setmainfont[Mapping=tex-text]{Liberation Serif}
\setsansfont[Mapping=tex-text]{Liberation Sans}
\setmonofont[Mapping=tex-text]{Liberation Mono}
%% Ensure sequential numbering of subsubsections.
\setsecnumdepth{paragraph}
\counterwithout{paragraph}{subsubsection}
\counterwithout{subsubsection}{subsection}
\renewcommand{\thechapter}{\arabic{chapter}}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\Roman{subsection}}
\renewcommand{\thesubsubsection}{\S\arabic{subsubsection}}
\setcounter{tocdepth}{3} % Must not precede the above
\titleformat{\paragraph}[hang]
{\raggedleft\normalfont\small\itshape\bfseries}{}{0pt}{#1
\arabic{paragraph}}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\chapter*{}
\section*{Beauty}
\label{sec:beauty}
\addcontentsline{toc}{section}{\nameref{sec:beauty}}
\section*{Preface}
\label{sec:preface}
\addcontentsline{toc}{section}{\nameref{sec:preface}}
\chapter*{First Grade}
\label{ch:firstgrade}
\addcontentsline{toc}{chapter}{\nameref{ch:firstgrade}}
\section*{Introduction}
\label{sec:intro}
\addcontentsline{toc}{section}{\nameref{sec:intro}}
\section{Outline}
\subsubsection{Charlie}
\paragraph{Exercise}
\paragraph{Exercise}
\subsubsection{Delta}
\section{Start}
\subsubsection{Continue}
\chapter*{Second Grade}
\label{ch:secondgrade}
\addcontentsline{toc}{chapter}{\nameref{ch:secondgrade}}
\setcounter{section}{0}
\setcounter{subsubsection}{0}
\section{Declension}
\subsubsection{Echo}
\paragraph{Exercise}
\paragraph{Exercise}
\end{document}
文档结构有点不寻常(它从节级开始,没有指定第一章,并且子节编号连续贯穿整个章节),但我无法修改。有两个麻烦:
(1)Echo
ToC 入口指向Charlie
,以及(直观,但仍然是错误Declension
的Outline
);
(2) Beauty
、Preface
和Introduction
ToC 条目似乎没有名称和链接,但First Grade
和Second Grade
章节条目可以。
希望有办法纠正事情。
答案1
书签
章节层次结构中有跳转:
\section{Outline}
\subsubsection{Charlie}
...
\section{Start}
\subsubsection{Continue}
subsection
缺少级别。 无法很好地处理此问题hyperref
,但可以通过重新设计包中的算法来解决bookmark
。 包应添加到包之后hyperref
,请参见下面的示例。
独特的锚点名称
链接的问题是由于锚点名称不唯一造成的。这是由于计数器重置造成的。计数器subsection
和subsubsection
都在重复使用其数字。但hyperref
需要唯一的数字来生成锚点名称,从而生成链接目标。
唯一性可以通过正确定义所\theH<counter>
使用的伴随宏hyperref
(如果可用)来提供。以下示例添加了一个宏,该宏将插入到for和\ChapterAnchorPrefix
的定义中。如果计数器被重置,则必须为其分配一个新值。\theH<counter>
section
subsection
\ChapterAnchorPrefix
示例(无内容titlesec
):
\documentclass[11pt,a4paper,oneside]{memoir}
%% Ensure sequential numbering of subsubsections.
\setsecnumdepth{paragraph}
\counterwithout{paragraph}{subsubsection}
\counterwithout{subsubsection}{subsection}
\renewcommand{\thechapter}{\arabic{chapter}}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\Roman{subsection}}
\renewcommand{\thesubsubsection}{\S\arabic{subsubsection}}
\setcounter{tocdepth}{3} % Must not precede the above
\usepackage{hyperref}
\usepackage{bookmark}
\newcommand*{\ChapterAnchorPrefix}{chapter}
\def\theHsection{\ChapterAnchorPrefix.\the\value{section}}
\def\theHsubsubsection{\ChapterAnchorPrefix.\the\value{subsubsection}}
\begin{document}
\tableofcontents
\chapter*{}
\section*{Beauty}
\label{sec:beauty}
\addcontentsline{toc}{section}{\nameref*{sec:beauty}}
\section*{Preface}
\label{sec:preface}
\addcontentsline{toc}{section}{\nameref*{sec:preface}}
\chapter*{First Grade}
\label{ch:firstgrade}
\addcontentsline{toc}{chapter}{\nameref*{ch:firstgrade}}
\section*{Introduction}
\label{sec:intro}
\addcontentsline{toc}{section}{\nameref*{sec:intro}}
\section{Outline}
\subsubsection{Charlie}
\paragraph{Exercise}
\paragraph{Exercise}
\subsubsection{Delta}
\section{Start}
\subsubsection{Continue}
\chapter*{Second Grade}
\label{ch:secondgrade}
\addcontentsline{toc}{chapter}{\nameref*{ch:secondgrade}}
\renewcommand*{\ChapterAnchorPrefix}{2G}
\setcounter{section}{0}
\setcounter{subsubsection}{0}
\section{Declension}
\subsubsection{Echo}
\paragraph{Exercise}
\paragraph{Exercise}
\end{document}