帮助格式化目录、左边距数字

帮助格式化目录、左边距数字

您好,我想删除目录条目左侧的一些数字。我使用的是文章类别,我想删除“部分”左侧的数字,但不删除“子部分”左侧的数字。因此,在下图中,我想保留“1.1、1.2 等”,但不保留“1”

在此处输入图片描述

文档本身也会出现这种情况,每个新章节的左侧都会列出编号。我想清除这些编号,但仍保留子章节编号。

我查看了 tocloft,但看不懂。如果您能提供任何帮助,那就太好了。我正在使用 Texstudio,这是我的文档现在的样子:

\documentclass[12pt, a4paper]{article}
\usepackage{baskervald}
\usepackage[T1]{fontenc}
\usepackage[notes]{biblatex-chicago}
\DefineBibliographyStrings{english}{references = {Works Cited}}
\DeclareBibliographyCategory{primary}
\usepackage{filecontents}
\usepackage{microtype}
\usepackage{url}
\usepackage{makeidx}
\usepackage{indentfirst}
\makeindex
\addbibresource{bibliography.bib}
\begin{document}
\tableofcontents
\newpage
\section{Part I}
\printbibliography[title={Primary Works},category=primary]
\end{document}

答案1

这是文档的最小版本;重要的代码位于和之间\makeatletter\makeatother基本上我们调用\l@section,它负责在消除后排版目录中的条目\numberline。然后我们重新定义\@seccntformat负责在章节标题旁边(在所有级别)打印数字的:因为我们只定义\sectionformat,所以\section{Part I}不会打印任何数字。

\documentclass[12pt, a4paper]{article}

\makeatletter
\let\latexl@section\l@section
\def\l@section#1#2{\begingroup\let\numberline\@gobble\latexl@section{#1}{#2}\endgroup}
\def\@seccntformat#1{\ifcsname #1format\endcsname\else\csname the#1\endcsname\quad\fi}
\def\sectionformat{}

\makeatother

\usepackage{hyperref}

\begin{document}
\tableofcontents
\newpage
\section{Part I}
\subsection{abc}
\subsection{def}
\end{document}

注意hyperref应该加载的修改\l@section(当然,如果你想加载它)。

在此处输入图片描述

在此处输入图片描述

红色矩形是由于hyperref

然而,我发现写“第一部分”并且用阿拉伯数字表示该章节的风格很糟糕。

答案2

(根据 egreg 的评论进行编辑,但我仍然更喜欢在 section 命令本身之前使用 \phantomsection。)此代码有效,但其他人可能可以制作一个更简单的版本。

\documentclass[12pt,a4paper]{article}

\usepackage{hyperref}

\begin{document}

\tableofcontents

\newpage

\phantomsection
\section*{Part I}
\addcontentsline{toc}{section}{Part I}
\stepcounter{section}
\subsection{abc}
\subsection{def}

\phantomsection
\section*{Part II}
\addcontentsline{toc}{section}{Part II}
\stepcounter{section}
\subsection{ghi}
\subsection{jkl}

\end{document}

相关内容