2

I have a not so far problem from the question opened here: Adding word "Chapter" into Table of Contents for only numbered chapter entries

I'm using a "literal numbering for chapters, using the macro:

\newcommand\words[1]{\expandafter\xwords\csname c@#1\endcsname}
\def\xwords#1{\ifcase#1\or
One\or
Two\or
Three\else
I need more words\fi}

%\usepackage{etoolbox} %% uncomment if 'etoolbox' isn't already being loaded
\makeatletter
\patchcmd{\@makechapterhead}{\thechapter}{\words{chapter}}{}{}
\makeatother

So I want to have in my table of contents

Chapter One. The title of the chapter one

Chapter Two. The title of the chapter two...and so

Solutions based on the two packages titletoc and tocloft are wellcome, preventing eventual problems of compatibility, because I'm using bidi package (For example, in the solution based on titletoc, in the question cited, one must change the value of \thecontentslabel command to the "literal" value, I think, but I don't know how !)

enter image description here

  • Should the way chapters are counted, i.e. the counter value is displayed, changed in the ToC only? The caveat of 'One', 'Two' is that the space required for this 'numbers' is larger than for real numbers. –  Nov 21 '14 at 07:22
  • Please look to the comments of the answer. Thanks – Faouzi Bellalouna Nov 21 '14 at 08:25
  • Which comments to which answer? –  Nov 21 '14 at 08:31

2 Answers2

5

The problem is solved, by using titletoc. I give n answer combined with a use of the package fncychap and option Glenn. Using the following commands on the examples given above, gives a good form...

\usepackage[Glenn]{fncychap}
\ChNumVar{\Large}% Dimension of the number of the chapter

\usepackage{titletoc}%
\titlecontents{chapter}% <section-type>
  [0pt]% <left>
  {\bfseries\vspace*{10pt}}% <above-code>
  {\large\chaptername\ \thecontentslabel. }% <numbered-entry-format>
  {}% <numberless-entry-format>
  {\hfill\contentspage}% <filler-page-format>


\makeatletter
\pretocmd{\@chapter}{\begingroup \renewcommand{\thechapter}{{\words{chapter}}}}{}{}
\apptocmd{\@chapter}{\endgroup}{}{}
\makeatother

Here's the first page of the contents (The enumeration obtained by \words is in arabic الأول الثاني الثالث and the chaptername in arabic is الباب)

enter image description here

One can see the difference with the first page on the beginning of the document.

The page 1 of the chapter 1

enter image description here

On the demand of @Educ I give the complete file, with some improvements, to produce what I'm talking about (partial contents, fancy things etc)

The .tex file

\documentclass[14pt,a4paper]{book}

\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{etoolbox}
\usepackage{multicol}
\usepackage{titleps}

\usepackage{amsmath,amssymb}

\usepackage{geometry}
\geometry{paperwidth=180mm, paperheight=130mm, top=5mm, bottom=5mm}
\pagestyle{empty}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.2,AutoFakeSlant=-0.02]{Traditional Arabic}
\setsansfont[Script=Arabic,Scale=1.5]{Traditional Arabic}

\makeatletter
\pretocmd{\@chapter}{\begingroup \renewcommand{\thechapter}{{\words{chapter}}}}{}{}
\apptocmd{\@chapter}{\endgroup}{}{}
\makeatother
\titlecontents{lsection}
  [2.3em]{\small}{\contentslabel{2.3em}}
  {\hspace*{-2.3em}}
  {}
\titlecontents{lsubsection}
  [4.6em]{\small}{\contentslabel{2.3em}}
  {\hspace*{-2.3em}}
  {}

\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries}{\chaptertitlename\ \words{chapter}}{20pt}{\Huge}
\titlespacing{\chapter}
  {0pt}{40pt}{-10pt}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  MACRO FOR LITERAL NUMBERING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\words[1]{\expandafter\xwords\csname c@#1\endcsname}
\def\xwords#1{\ifcase#1\or
الأول\or
الثاني\or
الثالث\or
الرابع\or
الخامس\or
السادس\or
السابع\or
الثامن\or
التاسع\or
العاشر\or
الحادي عشر\or
الثاني عشر\or
الثالث عشر\or
الرابع عشر\or
الخامس عشر\or
السادس عشر\or
السابع عشر\or
الثامن عشر\or
التاسع عشر\or
العشرون\or
\else
I need more words\fi}

% \usepackage{etoolbox} %% uncomment if 'etoolbox' isn't already being loaded
\makeatletter
\patchcmd{\@makechapterhead}{\thechapter}{\words{chapter}}{}{}
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  END MACRO FOR LITERAL NUMBERING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     REDEFINING NAMES IN ARABIC      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gappto\captionsarabic{\renewcommand{\contentsname}{المحتويات}}
\gappto\captionsarabic{\renewcommand{\chaptername}{الباب}}
\gappto\captionsarabic{\def\figurename{رسم}}
\gappto\captionsarabic{\renewcommand{\tablename}{جدول}}
\gappto\captionsarabic{\renewcommand{\indexname}{\textbf{الثبت}}}
\gappto\captionsarabic{\renewcommand{\appendixname}{\textbf{الملحق}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   MACRO FOR PARTIAL CONTENTS     %%%%%%%%%%%%%%%%%%%%%%%
% start of Werner's code
% http://tex.stackexchange.com/a/37732/3954
\setlength{\columnseprule}{0.1pt}
\makeatletter
\patchcmd{\endmulticols}{\par}{\par\xdef\@@tpd{\the\prevdepth}}{}{}
\newenvironment{multicolumns}[1]
  {% \begin{multicolumns}{<cols>}
   \par\nobreak % don't break a page here
   \kern\dimexpr\the\prevdepth+\multicolsep\relax % don't take into account the depth of the preceding line + #2
   {\columnseprulecolor\hrule height 0.4pt} % the rule, same width as \columnseprule
   \kern-\multicolsep % space after the rule
   \nointerlineskip % no additional space after the rule
   \begin{multicols}{#1}
  }
  {% \end{multicolumns}
   \end{multicols}%
   \par\nobreak % don't break a page here
   \kern\dimexpr\@@tpd-\multicolsep\relax % don't take into account the depth of the preceding line + #2
   {\columnseprulecolor\hrule height 0.4pt} % the rule, same width as \columnseprule
   \kern\multicolsep % space after the rule
   \nointerlineskip % no additional space after the rule
  }
\makeatother
% end of Werner's code

%%%     Commands for generateing the ptc
\newcommand\buildptc{%
\vspace*{-40pt}
  \startcontents[chapter]
{\large\noindent\bf
المحتوى}
\vspace*{-5pt}
  \begin{multicolumns}{2}
  \printcontents[chapter]{l}{0}{\setcounter{tocdepth}{1}}
  \end{multicolumns}%
%%%\vspace*{-40pt}
\vspace*{5pt}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   END MACRO FOR PARTIAL CONTENTS     %%%%%%%%%%%%%%%%%%%%%%%





%%%%%%%%%%%%%%%%%% REDEFINES \THECHAPTER IN CONTENTS
\makeatletter
\pretocmd{\@chapter}{\begingroup \renewcommand{\thechapter}{{\words{chapter}}}}{}{}
\apptocmd{\@chapter}{\endgroup}{}{}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \usepackage{titletoc}%
\titlecontents{chapter}% <section-type>
  [0pt]% <left>
  {\bfseries\vspace*{10pt}}% <above-code>
  {\normalsize\chaptername\ \thecontentslabel.\;}% <numbered-entry-format>
  {}% <numberless-entry-format>
  {\normalsize\hfill\contentspage}% <filler-page-format>

\usepackage[Glenn]{fncychap}
\ChNumVar{\Large}% Dimension of the number of the chapter in the first page... instead of the default...\ChNumVar{\Huge}

\begin{document}
\chapter{التحليل التوافقي}
\buildptc
\section{مقدّمة}
\section{المبدأ الأساسي للعد}

\chapter{مسلّمات الاحتمالات}
\buildptc
\section{مقدّمة}
\section{فراغ العينة و الحوادث} 
\section[مسلّمات الاحتمالات]{مسلّمات الاحتمالات\hfill\normalsize \LR{Axioms of Probability}} 
\stopcontents[chapter]
\end{document}

and it's compilation, with xelatex

enter image description here

enter image description here

  • 2
    Well, it's nice that you grab my efforts to improve your solution which I couldn't since I did not have to information you have ;-) –  Nov 24 '14 at 13:17
  • Many thanks. I post the first page of the chapter 1, with the minitoc obtained by this beautiful macro, which announces the next chapter, in bold... – Faouzi Bellalouna Nov 24 '14 at 20:33
  • @FaouziBellalouna could you send me the code of last page that u posted please if you agree i ll give you my email – Educ Feb 21 '17 at 13:15
  • @Educ It was a discussion more than 2 years ago, and I'm not sure that I'll find these code... I'll see – Faouzi Bellalouna Feb 21 '17 at 15:54
  • thank you since i have problem with fancy chapter and polygossia if you could help me here please http://tex.stackexchange.com/questions/354973/fncychap-and-polyglossia – Educ Feb 21 '17 at 15:56
  • @Educ see my edit – Faouzi Bellalouna Feb 21 '17 at 16:50
  • +1 thank you bro but could you keep the style of \usepackage[Glenn]{fncychap} i mean the box around the chapter – Educ Feb 21 '17 at 17:16
  • 1
    see the doc of the package... you can find the following...

    The following settings have been used as default parameters \ChNameVar{\bfseries\Large\sf}, \ChNumVar{\Huge}, \ChTitleVar{\bfseries\Large\rm}, \ChRuleWidth{1pt}, \ChNameUpperCase, \ChTitleUpperCase..

    you can play with this for adjustments...

    – Faouzi Bellalouna Feb 21 '17 at 17:25
  • 1
    I saw your opened question, and I was not very patient in my solution using fncychap... one must put the command after the other concerning sectioning... so just before document if you want..

    \usepackage[Glenn]{fncychap} \ChNumVar{\Large}% Dimension of the number of the chapter in the first page... instead of the default...\ChNumVar{\Huge}

    – Faouzi Bellalouna Feb 21 '17 at 17:36
  • 1
    I've forgotten another thing... must add the command \stopcontents[chapter] in the end of the last chapter, for a good behaviour of the partial contents.. I'll put it in the last edition ! – Faouzi Bellalouna Feb 22 '17 at 05:22
  • @FaouziBellalouna Salam bro, It works like a charm thank you for everything, May Allah bless you. – Educ Feb 22 '17 at 06:49
  • @Educ You're welcome. Happy texifying – Faouzi Bellalouna Feb 22 '17 at 07:01
  • please what i can do to this: Don't shape 'TU/TraditionalArabic(0)/bx/n'undefined(Font) – Vrouvrou Aug 14 '18 at 19:26
  • @Faouzi BEllalouna it appears to me like a beamer not lie a book please help me what I must do? – Vrouvrou Aug 15 '18 at 14:44
  • @Vrouvrou Sorry but I just saw your message. I don't understand your question. What do you want to do exactly ? – Faouzi Bellalouna Aug 20 '18 at 21:24
2

A possible solution, but I am sure, this has been answered before

(I took the \cftchapresnum... etc code from Karl Koeller's answer in the link provided by the OP)

\documentclass{book}

\usepackage{fmtcount}
\usepackage{blindtext}
\usepackage[titles]{tocloft}


\usepackage{forloop}

\newcounter{dummycounter}%

\newlength\mylength
\renewcommand\cftchappresnum{\chaptername~}
\renewcommand\cftchapaftersnum{:}
\settowidth\mylength{\cftchappresnum\cftchapaftersnum\quad\quad 5pt}
\addtolength\cftchapnumwidth{\mylength}

\usepackage{etoolbox}%


\makeatletter
\pretocmd{\@chapter}{\begingroup \renewcommand{\thechapter}{\Numberstring{chapter}}}{}{}
\apptocmd{\@chapter}{\endgroup}{}{}
\makeatother


\begin{document}
\tableofcontents

\forloop{dummycounter}{1}{\value{dummycounter} < 11}{%
\chapter{Some Content of chapter \number\value{dummycounter}}%
\blindtext[5]
}%
\end{document}

enter image description here

  • Your answer seems to be the good solution for me. But there's some details that I want to talk about... I go to the discuss on my original file which is in arabic, using polyglossia. I try to make it comprehensive for you. Thanks – Faouzi Bellalouna Nov 21 '14 at 08:35
  • I give the first page of my contents (of a very beautiful book of probability in arabic in the end of progress...), with some explanation... The chaptername in arabic is الباب... "First" is الأول and "Second" is الثاني... All is written from right to left... You can see that the contents of level "chapter" have gone far in the margin... How can I push it to the left... Same thing for the level "subsection" (pages 18,19,23...)... The contents for the sections are in the right place ...Why is it not the case for the others? – Faouzi Bellalouna Nov 21 '14 at 08:54
  • @FaouziBellalouna: Sorry, I don't understand Arabic and have never worked with polyglossia so far –  Nov 21 '14 at 08:58
  • ok thanks.. I'll try to my self and inform you – Faouzi Bellalouna Nov 21 '14 at 08:58
  • @FaouziBellalouna: The problem is rather that you use a lot of extra packages/formatting which is not provided to us. –  Nov 21 '14 at 09:06
  • @FaouziBellalouna: I don't understand what you mean –  Nov 21 '14 at 20:24
  • Thanks to your idea, I've worked on the solution you proposed and adapted it to my packages, working with bidi... I gave the solution to my question. Many thanks. – Faouzi Bellalouna Nov 21 '14 at 22:10
  • (+1) @FaouziBellalouna The way to thank somebody on this site is to accept and/or upvote their answer. It is not at all nice to instead grab the person's code and post it as part of your own solution, especially if the person could not reasonably have been expected to be of more help given the information provided in your question (which did not even include a Minimum Working Example). – cfr Nov 28 '14 at 17:44
  • @cfr: Thanks for your support, but it was not my intention to get the upvote/accept for this answer in particular, but there so many answers from other users here which has not been accepted/upvoted (I suppose?) by the OP –  Nov 28 '14 at 17:47
  • @ChristianHupfer Sorry. It was just chance that I looked at this question in particular. Your comment did cause me to look at the user's list of questions but I just picked one which had a couple of answers. I wasn't looking for one you had answered (and didn't know you had when I picked this one - it was listed as last modified by the user). – cfr Nov 28 '14 at 17:49