1

I've faced some issues when making my ToC. I don't want the number before "Part" to be shown, but the code I'm using right now messes up with the configuration that allows me to reset the ennumeration to the Chapters on each Part.

Here's my code

\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}

Currently my ToC looks like this:

I "Title Part 1"
chapter 1
chapter 2
II "Title Part 2"
chapter 3
chapter 4

This is similar to whan I'm looking for.

"Title Part 1"
chapter 1
chapter 2
"Title Part 2"
chapter 1
chapter 2
Chanchy
  • 13

1 Answers1

0

You cannot reset the chapter numbering with \makeatletter\@addtoreset{chapter}{part}\makeatother because you use starred part, so the counter of part don't change.

For the same reason \counterwithin*{chapter}{part} (from the package chngcntr) don't work here.

But the package xpatch (which you already uses in your code) can help here, with the code \xpretocmd{\part}{\setcounter{chapter}{0}}{}{} (thanks to https://tex.stackexchange.com/a/271079/132405).

I remove some things from your code, unrelated to your problem (also, there is a \restoregeometry in your code without \usepackage{geometry}, and a \include{front.tex} which we don't have so your code don't compile without error).

\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}

Result:

enter image description here

quark67
  • 4,166
  • Thank you very much for your will, it works very well. You even helped me solve other doubts I had. I am very grateful. – Chanchy Mar 01 '23 at 04:41
  • Fell free to accept my answer by clicking on the check mark if my solution works for you. – quark67 Mar 01 '23 at 04:44