2

The title may seems unclear.

I have a document with several parts, including several chapters. I want the numbering of the chapter to be reset after each new part (easy) BUT : - I want the header of my chapter to be just the number of the chapter (not Part.Chapter) - I want the ToC to show the same thing (not the part number for each chapter and section) - I want the ref to a chapter or a section to be Part.Chap(.sec etc).

Here is a MWE with the package I use in my thesis. It looks almost fine. Just the reference to chapter "I.1" does not work.

\documentclass[twoside,12pt,openright,a4paper,usenames,dvipsnames]{book}
\usepackage[linktoc=all,hyperindex]{hyperref}
\usepackage{chngcntr}
\counterwithin{chapter}{part}

\usepackage{titlesec}
\usepackage[titles]{tocloft}
\titleformat{name=\chapter}[display]
{\bfseries\LARGE}
{\filleft\MakeUppercase{\chaptertitlename} \Huge\thechapter}
{0ex}
{%\titlerule
\vspace{2ex}%
\filleft}
[\vspace{4ex}%
\titlerule]

\titleformat{name=\chapter,numberless}
{\bfseries\LARGE}
{}
{0ex}
{%\titlerule
\filleft\MakeUppercase}
[\vspace{4ex}%
\titlerule]
\titlespacing*{\chapter}{0pt}{-25pt}{40pt}

\titleformat{\part}[frame]
{\bfseries\Huge}
{\filright\large\enspace{\partname}\enspace}
{40pt}
{\Large\filcenter\MakeUppercase}
\titleclass{\part}{top}

\begin{document}

\tableofcontents

\part{Part 1}

\chapter{Chap 1}

\label{chap:chapI1}

\chapter{Chap 2}

\part{Part 2}

\chapter{Chap 1}

As mentioned in chap.~\ref{chap:chapI1},...

\chapter{Chap 2}

\end{document}

Do you know how I can fix the refs ? I browsed similar question, but none answer in the case of titlesec use.

  • this was answered (here), i'll search (with you) – touhami Apr 25 '15 at 7:39
  • Sorry but I don't understand the answer (or you forgot the hyperlink perhaps?) – Basil1402 Apr 25 '15 at 7:52
  • i mean this question was answerd in this site, i will search for the link and in this time you can do the same. now i post an answer with the link – touhami Apr 25 '15 at 8:00
2

here 2 solutions:

with

\usepackage{chngcntr}
\counterwithin{chapter}{part}

use

\makeatletter
\renewcommand{\thechapter}{\@arabic\c@chapter}
\renewcommand{\p@chapter}{\thepart.}
\makeatother

without it use

\makeatletter
\@addtoreset{chapter}{part}
\renewcommand{\p@chapter}{\thepart.}
\makeatother

Edit for appendix, replace

\renewcommand{\p@chapter}{\thepart.}

by

\renewcommand{\p@chapter}{%
\ifx\@chapapp\chaptername\thepart.\fi}

the answer i was refering is here

| improve this answer | |
  • I forgot one detail... I would need my figures and tables to be numbered with the part number as well (if not, I have several figures numbered 1.1., 1.2, etc). I am using the tocloft package by the way. Do you know a way? – Basil1402 Apr 26 '15 at 8:04
  • Just a tip : if you have appendixes in an unnumbered part, add the lines \makeatletter \renewcommand{\p@chapter}{} \makeatother before the first appendix. Like that, your appendixes will not be numbered with the last part number. – Basil1402 Apr 26 '15 at 8:22
  • @Basil1402 try this \renewcommand\thefigure{\thepart.\thechapter.\arabic{figure}} what about appendix can you explan – touhami Apr 26 '15 at 8:30
  • Thanks. For the appendixes, here is what I mean. I used the preamble above and, after my final main part, I wrote several appendixes (A, B, C...) included in an unumberbed part (\part*{Appendixes}). With the template above, if I make a reference to the appendixes in the main text, it will be noted, e.g., "see App. III.B" where III is the number of my last main part. Not very clever. So, just by adding \makeatletter \renewcommand{\p@chapter}{} \makeatother before \part*{Appendixes}, it makes the cross-referencing to appendixes right, eg. "see App. B". – Basil1402 Apr 26 '15 at 8:45
  • @Basil1402 I add this to my answer. – touhami Apr 26 '15 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.