格式化 \Cref 影响目录

格式化 \Cref 影响目录

我最近获得了格式化方面的帮助小节数字而不改变参考数字。(如何在不影响参考文献的情况下缩进文本中的小节?) 正是按照我的要求做的。

不幸的是,我的工作示例既不包括 abook table of contents也不包括 a chapter table of content,我刚刚发现book tocchapter toc列表 the小节我不想要这个。

此外,还有一些奇怪的事情:chapter 1 toc以“chapter.1”开头,虽然chapter 2 toc应该是空的,但它是未格式化的副本chapter 1 toc(以及前面的“chapter.1”)。

当然,这些都与建议的格式代码没有任何关系。

以下是 MWE:

\documentclass[11pt]{book}
\usepackage{titlesec} 
    \titleformat{\subsection}[runin]{\normalfont\large\bfseries}{\hspace{10mm}\arabic{subsection}.}{1mm}{}{}
\usepackage[hyperfootnotes=false]{hyperref}%
\usepackage{cleveref}%
    \Crefname{subsection}{Subsection}{Subsections}  
\usepackage[dotinlabels]{titletoc}
    \titlecontents{chapter}[6pc]{\addvspace{1pc}\bfseries\filright}{\contentslabel[\chaptername\ \thecontentslabel]{6pc}}{}{\hfill\contentspage}[\addvspace{2pt}]%
    \newcommand\xquad{\hspace{0.4em plus .2em minus .2em}}%
    \titlecontents*{p-section}[0pt]{\filright\small}{}{}{,\thecontentspage}[\xquad\textbullet\xquad][.]%
    \newcommand{\ChapterToc}{\startcontents[chapters]\printcontents[chapters]{p-}{1}{}\vspace{10mm}}%

\begin{document}
         \tableofcontents

\chapter{Numbers}\label{1-0-0}
\ChapterToc

Some prefatory text
\section{Plain Numbers}\label{1-1-0}
\subsection{Definition}\label{1-1-1}
text text text text text text  
\subsection{Properties}\label{1-1-2}
text text text text text text  

\section{Signed Numbers}\label{1-2-0}
text text text text text text text text text text text text text text 
\subsection{Definition}\label{1-2-1}
text text text text text text  
\subsection{Properties}\label{1-2-2}
text text text text text text  


\chapter{Functions}\label{2-0-0}
\ChapterToc

Some text and now some references:

\Cref{1-0-0} \nameref{1-0-0}

\Cref{1-1-0} \nameref{1-1-0}

\Cref{1-1-1} \nameref{1-1-1}

\end{document}

输出如下:

在此处输入图片描述

答案1

正如 Christian 所提到的,您必须加载除cleveref之前之外的所有包hyperrefcleveref应该在之后加载hyperref

如果只有章节目录不应该列出小节,那么您可以使用的最后一个参数\printcontents进行tocdepth本地更改:

\printcontents[chapters]{p-}{1}{\setcounter{tocdepth}{1}}

在此处输入图片描述

代码:

\documentclass[11pt]{book}
\usepackage{titlesec} 
    \titleformat{\subsection}[runin]{\normalfont\large\bfseries}{\hspace{10mm}\arabic{subsection}.}{1mm}{}{}

\usepackage[dotinlabels]{titletoc}
    \titlecontents{chapter}[6pc]{\addvspace{1pc}\bfseries\filright}{\contentslabel[\chaptername\ \thecontentslabel]{6pc}}{}{\hfill\contentspage}[\addvspace{2pt}]%
    \newcommand\xquad{\hspace*{0.4em plus .2em minus .2em}}%
    \titlecontents*{p-section}[0pt]{\filright\small}{}{}{, \thecontentspage}[\xquad\textbullet\xquad][.]%
    \newcommand{\ChapterToc}{\startcontents[chapters]\printcontents[chapters]{p-}{1}{\setcounter{tocdepth}{1}}\vspace{10mm}}%

\usepackage[hyperfootnotes=false]{hyperref}%
\usepackage{cleveref}% should be the last package
    \Crefname{subsection}{Subsection}{Subsections}

\begin{document}
\tableofcontents
\chapter{Numbers}\label{1-0-0}
\ChapterToc
Some prefatory text
\section{Plain Numbers}\label{1-1-0}
\subsection{Definition}\label{1-1-1}
text text text text text text  
\subsection{Properties}\label{1-1-2}
text text text text text text  
\section{Signed Numbers}\label{1-2-0}
text text text text text text text text text text text text text text 
\subsection{Definition}\label{1-2-1}
text text text text text text  
\subsection{Properties}\label{1-2-2}
text text text text text text  

\chapter{Functions}\label{2-0-0}
\ChapterToc
Some text and now some references:

\Cref{1-0-0} \nameref{1-0-0}

\Cref{1-1-0} \nameref{1-1-0}

\Cref{1-1-1} \nameref{1-1-1}
\end{document}

如果要从所有目录中删除子部分,则进行tocdepth全局更改:

\documentclass[11pt]{book}
\usepackage{titlesec} 
    \titleformat{\subsection}[runin]{\normalfont\large\bfseries}{\hspace{10mm}\arabic{subsection}.}{1mm}{}{}

\usepackage[dotinlabels]{titletoc}
    \titlecontents{chapter}[6pc]{\addvspace{1pc}\bfseries\filright}{\contentslabel[\chaptername\ \thecontentslabel]{6pc}}{}{\hfill\contentspage}[\addvspace{2pt}]%
    \newcommand\xquad{\hspace*{0.4em plus .2em minus .2em}}%
    \titlecontents*{p-section}[0pt]{\filright\small}{}{}{, \thecontentspage}[\xquad\textbullet\xquad][.]%
    \newcommand{\ChapterToc}{\startcontents[chapters]\printcontents[chapters]{p-}{1}{}\vspace{10mm}}%

\usepackage[hyperfootnotes=false]{hyperref}%
\usepackage{cleveref}% should be the last package
    \Crefname{subsection}{Subsection}{Subsections}

\setcounter{tocdepth}{1}% <- only parts, chapters and sections in tocs
\begin{document}
\tableofcontents
\chapter{Numbers}\label{1-0-0}
\ChapterToc
Some prefatory text
\section{Plain Numbers}\label{1-1-0}
\subsection{Definition}\label{1-1-1}
text text text text text text  
\subsection{Properties}\label{1-1-2}
text text text text text text  
\section{Signed Numbers}\label{1-2-0}
text text text text text text text text text text text text text text 
\subsection{Definition}\label{1-2-1}
text text text text text text  
\subsection{Properties}\label{1-2-2}
text text text text text text  

\chapter{Functions}\label{2-0-0}
\ChapterToc
Some text and now some references:

\Cref{1-0-0} \nameref{1-0-0}

\Cref{1-1-0} \nameref{1-1-0}

\Cref{1-1-1} \nameref{1-1-1}
\end{document}

相关内容