我在制作目录时遇到了一些问题。我不想显示“部分”前面的数字,但我现在使用的代码与允许我将枚举重置为每个部分的章节的配置相冲突。
这是我的代码
\documentclass[10pt,twoside]{book}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\usepackage{chngcntr}
\usepackage{textcomp}
\usepackage{mathptmx}
\usepackage{amstext}
\usepackage{amssymb}
%\makeatletter\@addtoreset{chapter}{part}\makeatother% %reiniciar los capitulos por parte
% This creates a header on your document---more specifically, a "fancy" header. Specific header info is specified below
\usepackage{fancyhdr}
\pagestyle{fancy}
\headsep=12pt
\headheight=15pt
% This sets special formatting for section titles and such, if you want to create special ones
\usepackage{titlesec}
\titleformat{\section}
{\normalfont\normalsize\bfseries\centering}{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\normalsize\itshape}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\normalsize\itshape}{\thesubsubsection}{1em}{}
\renewcommand{\thechapter}{\Roman{chapter}}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{xpatch}
\usepackage{blindtext}
\makeatletter
\setlength\parskip{1ex}
\usepackage{lipsum}
\usepackage[titles]{tocloft}%
\renewcommand{\cftchapleader}{~\cftdotfill{5}}
\setcounter{secnumdepth}{0}
\setcounter{tocdepth}{3}
\renewcommand{\contentsname}{Whatever}
\counterwithin*{chapter}{part}
%\cftsetindents{part}{2.5em}{0em}
\cftsetindents{subsection}{0.5em}{0em}
\makeatletter
\@addtoreset{chapter}{part}
\makeatother
\renewcommand{\cftchapaftersnum}{.}
\addtolength{\cftchapnumwidth}{10pt}
%\renewcommand{\thechapter}{\roman{chapter}}
%\titleformat{\chapter}{\normalfont\large\bfseries}{\thechapter.}{1em}{}
% to center part
\renewcommand{\cftpartfont}{\hfill\large\bfseries}
\usepackage{xpatch}
\makeatletter
\patchcmd{\l@part}{#1}{#1\hfill\hskip-\rightskip\mbox{}}{}{}
\makeatother
\addtocontents{toc}{\cftpagenumbersoff{part}}
\usepackage{titlesec}
\begin{document}
\frontmatter
\include{front.tex}
\thispagestyle{plain}
\restoregeometry
\pagenumbering{gobble}
\thispagestyle{empty}
\pagenumbering{arabic}
\tableofcontents
\mainmatter
\addcontentsline{toc}{part}{title part 1}
\part*{title part 1}
\chapter{A}
\chapter{B}
\chapter{C}
\addcontentsline{toc}{part}{title part 2}
\part*{title part 2}
\chapter{A}
\chapter{B}
\chapter{C}
\end{document}
目前我的目录如下所示:
I "Title Part 1"
chapter 1
chapter 2
II "Title Part 2"
chapter 3
chapter 4
这与我所寻找的类似。
"Title Part 1"
chapter 1
chapter 2
"Title Part 2"
chapter 1
chapter 2
答案1
由于您使用带星号的部分,因此您无法重置章节编号\makeatletter\@addtoreset{chapter}{part}\makeatother
,所以部分的计数器不会改变。
出于同样的原因\counterwithin*{chapter}{part}
(从包更改中心) 在这里不起作用。
但包裹补丁(您已经在代码中使用了它)可以在这里提供帮助,代码如下\xpretocmd{\part}{\setcounter{chapter}{0}}{}{}
(感谢https://tex.stackexchange.com/a/271079/132405)。
\restoregeometry
我从您的代码中删除了一些与您的问题无关的内容(此外,您的代码中有一个没有的\usepackage{geometry}
,以及一个\include{front.tex}
我们没有的 ,因此您的代码无法编译而出现错误)。
\documentclass[10pt,twoside]{book}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
% This creates a header on your document---more specifically, a "fancy" header. Specific header info is specified below
\usepackage{fancyhdr}
\pagestyle{fancy}
\headsep=12pt
\headheight=15pt
\renewcommand{\thechapter}{\Roman{chapter}}
\pagestyle{fancy}
\usepackage{xpatch}
\xpretocmd{\part}{\setcounter{chapter}{0}}{}{}
\usepackage[titles]{tocloft}%
\renewcommand{\cftchapleader}{~\cftdotfill{5}}
\renewcommand{\cftchapaftersnum}{.}
\addtolength{\cftchapnumwidth}{10pt}
% to center part
\renewcommand{\cftpartfont}{\hfill\large\bfseries}
\makeatletter
\patchcmd{\l@part}{#1}{#1\hfill\hskip-\rightskip\mbox{}}{}{}
\makeatother
\addtocontents{toc}{\cftpagenumbersoff{part}}
\usepackage{titlesec}
\begin{document}
\frontmatter
Inclusion of front.tex
\thispagestyle{plain}
\pagenumbering{gobble}
\thispagestyle{empty}
\pagenumbering{arabic}
\tableofcontents
\mainmatter
\addcontentsline{toc}{part}{title part 1}
\part*{title part 1}
\chapter{A}
\chapter{B}
\chapter{C}
\addcontentsline{toc}{part}{title part 2}
\part*{title part 2}
\chapter{A}
\chapter{B}
\chapter{C}
\end{document}
结果: