目录中的章节编号

目录中的章节编号

我有一个与此处提出的问题相差不远的问题: 在目录中仅针对编号章节条目添加单词“章节”

我正在使用“章节的文字编号,使用宏:

\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

所以我想在我的目录中

第一章. 第一章标题

第二章第二章的标题……等等

基于两个包 titletoc 和 tocloft 的解决方案很受欢迎,可以防止最终出现兼容性问题,因为我使用的是 bidi 包(例如,在基于 titletoc 的解决方案中,在所引用的问题中,我认为必须将 \thecontentslabel 命令的值更改为“文字”值,但我不知道如何做!)

在此处输入图片描述

答案1

这是一个可能的解决方案,但我确信之前已经回答过这个问题

(我\cftchapresnum...从 OP 提供的链接中的 Karl Koeller 的回答中获取了等代码)

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

在此处输入图片描述

答案2

通过使用 titletoc,问题得以解决。我结合使用包 fncychap 和选项 Glenn 给出了答案。在上面给出的示例上使用以下命令,可以得到一个很好的形式...

\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

这是内容的第一页(\words 获得的枚举为阿拉伯语 الأول الثاني الثالث 并且章节名称的阿拉伯语名称为 الباب)

在此处输入图片描述

从文档的开头就能看出与第一页的区别。

第 1 章第 1 页

在此处输入图片描述

根据@Educ 的要求,我提供了完整的文件,并进行了一些改进,以产生我所谈论的内容(部分内容,花哨的东西等)

.tex 文件

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

使用 xelatex 进行编译

在此处输入图片描述

在此处输入图片描述

相关内容