5

I want to numbering the title of my chapters in a different manner and with my selected word. For example, I want my first chapter numbered AA and the second one FR and etc. How can I do that . My code is:

 \documentclass[a4paper, 11pt]{book}
\usepackage[english]{babel}
\usepackage{geometry}
\usepackage{pstricks}
\usepackage{graphicx}
\usepackage[doublespacing]{setspace}
\usepackage{romannum}
\usepackage{titlesec}

\renewcommand\thechapter{\Roman{chapter}}


\titleformat{\chapter}
  {\normalfont\fontsize{20}{15}\bfseries}
  {\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titleformat{\section}
  {\normalfont\fontsize{20}{15}\bfseries}
  {\thesection}{1em}{} 


\begin{document}
\chapter{Apple}
It is for test
\Chapter{Book}

\end{document}
4
  • 1
    Not recommending this: \renewcommand{\thechapter}{AA} etc. separately for each of the 'special' 'numbering' occurences. There is a typo: \Chapter\chapter. Since AA is followed by FR I can't see a definitive scheme in order to calculate such a chapter 'number'
    – user31729
    Commented Mar 1, 2018 at 10:44
  • @ChristianHupfer : Is there any command that I change seperate numbers of any chapter to my favorites. For example, change {Chapter #1} to {Chapter AA}, {Chapter #2} to {Chapter FR}, and etc
    – Astrolabe
    Commented Mar 1, 2018 at 10:53
  • Are you sticking to titlesec?
    – user31729
    Commented Mar 1, 2018 at 10:57
  • @ChristianHupfer : No, there is no insistence on it.
    – Astrolabe
    Commented Mar 1, 2018 at 11:09

3 Answers 3

3

I've defined a \seq variable that contains a list of desired numbers or 'texts' that should be used as numbers. The numbers are retrieved by the real chapter number with \seq_item:Nn, more can be added with \addtonumberpool (see code below).

This solution takes care of the ToC and the reference format.

\documentclass[a4paper, 11pt]{book}
\usepackage[english]{babel}
\usepackage{geometry}
\usepackage{pstricks}
\usepackage{graphicx}
\usepackage[doublespacing]{setspace}
\usepackage{romannum}
\usepackage{tocloft}
\addtolength{\cftchapnumwidth}{20pt}
\usepackage{xpatch}
\usepackage{xparse}

\ExplSyntaxOn

\seq_new:N \g_raihaneh_numberpool_seq

\NewDocumentCommand{\addtonumberpool}{+m}{%
  \group_begin:
  \seq_set_from_clist:Nn \l_tmpa_seq {#1}%
  \seq_map_inline:Nn \l_tmpa_seq {
    \seq_gput_right:Nn \g_raihaneh_numberpool_seq {##1}
  }
  \group_end:
}

\NewDocumentCommand{\populatenumberpool}{+m}{%
  \addtonumberpool{#1}
}


\makeatletter
\cs_new:Npn \mychapternumberexpression {%
  \cs_set:Npx \thechapter {\seq_item:Nn \g_raihaneh_numberpool_seq  {\int_eval:n {\value{chapter}+1}}}
}


\xpretocmd{\@chapter}{%
  \mychapternumberexpression
}{}{}

\makeatother

\ExplSyntaxOff

\populatenumberpool{AA,FR}

\addtonumberpool{BAD,TYPOGRAPHY}



\begin{document}
\tableofcontents

See \ref{apple} or \ref{book} or \ref{stuff}

\chapter{Apple} \label{apple}
It is for test
\chapter{Book} \label{book}

\chapter{Stuff} \label{stuff}

\end{document}

enter image description here

1
  • Wouldn't \clist_map_inline:nn { #1 } { \seq_gput_right:Nn \g_raihaneh_numberpool_seq {##1} } be simpler?
    – egreg
    Commented Mar 1, 2018 at 12:41
3

Inspired by your typo, \Chapter, I defined a command \Chapter that takes two arguments, the "number" of the chapter and its title.

Then I changed the \titleformat to make it use the "number" of the chapter that you give.

If you use a normal \chapter, the actual chapter number is used instead.

Beware! As @ChristianHupfer noted, even if you use \Chapter{FR}{Book}, in the table of contents it still will be Chapter II Book. His answer takes care of the ToC numbering too :)

enter image description here

\documentclass[a4paper, 11pt]{book}
\usepackage[english]{babel}
\usepackage{geometry}
\usepackage{pstricks}
\usepackage{graphicx}
\usepackage[doublespacing]{setspace}
\usepackage{romannum}
\usepackage{titlesec}

\renewcommand\thechapter{\Roman{chapter}}

\edef\chaptersymbol{}%
\newcommand{\Chapter}[2]{%
\edef\chaptersymbol{#1}%
\chapter{#2}%
\edef\chaptersymbol{}%
}

\titleformat{\chapter}
  {\normalfont\fontsize{20}{15}\bfseries}
  {\chaptertitlename\ \ifx\chaptersymbol\empty\thechapter\else\chaptersymbol\fi}{20pt}{\Huge}
\titleformat{\section}
  {\normalfont\fontsize{20}{15}\bfseries}
  {\thesection}{1em}{} 


\begin{document}
\chapter{Apple}
It is for test
\Chapter{FR}{Book}

\end{document}
2
  • 1
    Your solution does provide 'wrong' chapter numbers in the ToC and with \ref....
    – user31729
    Commented Mar 1, 2018 at 11:17
  • @ChristianHupfer Hmmm, indeed. I didn't think of that :/ Commented Mar 1, 2018 at 11:36
0

You can simply define the sequence of the chapter numbers and redefine accordingly \thechapter:

\documentclass{book}

\usepackage{xparse}
\usepackage{etoolbox}

\ExplSyntaxOn
\NewDocumentCommand{\definechapternumbers}{m}
 {
  \clist_gset:Nn \g_raihaneh_chapters_clist { #1 }
 }
\RenewExpandableDocumentCommand{\thechapter}{}
 {
  \clist_item:Nn \g_raihaneh_chapters_clist { \value{chapter} }
 }
\ExplSyntaxOff

\definechapternumbers{AA,FR}

% make a bit more room for the chapter numbers in the TOC
\makeatletter
\patchcmd{\l@chapter}{1.5em}{2.5em}{}{}
\makeatother

\begin{document}

\let\cleardoublepage\relax % just not to have page breaks

\tableofcontents

\chapter{Apple}\label{chap:apple}

This is chapter~\ref{chap:apple}

\chapter{Book}\label{chap:book}

This is chapter~\ref{chap:book}

\end{document}

enter image description here

1
  • it depends, if you want to define the chapter numbering independently of the chapter name. Then, having a number pool in some centralized location is desirable. But, if like in Phelype's answer, you want the numbering close to the chapter name, i. e., in the same location, then having a macro with two options is nicer. Depends on the OP's doc design, I guess. In any case, having the correct labels in the TOC is paramount, as otherwise, it's just confusing for the readers. Nicely done (I would so much love to learn expl syntax!).
    – thymaro
    Commented Mar 1, 2018 at 20:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .