章节编号中的序数

章节编号中的序数

我正在写日记,我希望每个 \chapter 编号都包含一个序数指示符(st、nd、rd 等)。请参阅附图作为示例(我用红色标记了我要查找的内容)。有没有办法在 LaTeX 中实现此功能?因此,对于每一章,LaTeX 都应根据数字输出序数指示符。因此,对于第“2”章,它将是“2nd”,对于“330”,它将是“330th”。

在此处输入图片描述

\documentclass[11pt,twoside,openright]{book}
\usepackage[paperheight=8.5in,paperwidth=5.5in]{geometry}
\geometry{showframe=false}
\geometry{margin=0.5in,bottom=0.70in, top=0.50in, bindingoffset=0.2in}
\usepackage[super,comma]{natbib}
\usepackage{setspace}
\renewcommand{\baselinestretch}{1.15} 
\usepackage{url}
\usepackage{amssymb,amsmath,amsthm,amsfonts}
\usepackage{blindtext} % tor the example text
\usepackage{titlesec}
\usepackage{emptypage}
\usepackage{fancyhdr}
\usepackage{pifont}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{tabularx}
\usepackage{fontawesome}
\usepackage{tikz}
\usepackage{subfigure}
\usepackage{colortbl}
\usepackage{pdfpages}
\usepackage{multicol}
\usepackage{lettrine}
\usepackage{titlesec}
\usepackage{wrapfig}
\usepackage{graphicx}
\usepackage{lipsum}
\renewcommand{\labelitemi}{$\rhd$}
\usepackage{booktabs}
\usepackage[svgnames,table]{xcolor}
\usepackage[tableposition=above]{caption}
\usepackage{pifont}
\usepackage{tex4ebook}

%%% Chapter Heading %%%
\makeatletter
\def\thickhrule{\leavevmode \leaders \hrule height 0.5ex \hfill \kern \z@}
\def\position{\centering}
%% Note the difference between the commands the one is 
%% make and the other one is makes
\renewcommand{\@makechapterhead}[1]{%
  \vspace*{0.5\p@}%
  {\parindent \z@ \position \reset@font
        {\huge \scshape \thechapter}
        \par\nobreak
        \vspace*{5\p@}%
        \interlinepenalty\@M
        \thickhrule
        \par\nobreak
        \vspace*{2\p@}%
        {\large \bfseries #1\par\nobreak}
        \par\nobreak
        \vspace*{2\p@}%
        \thickhrule
        \vskip 10\p@
  }}

\begin{document}

\chapter{Title name}

\end{document}

答案1

我建议你使用计数包来实现章节编号的格式化目标。

在此处输入图片描述

如何进一步“装饰”章节标题是一个最好留给另一个包的主题,例如标题安全包裹。

\documentclass[11pt,twoside,openright]{book}
\usepackage[paperheight=8.5in,paperwidth=5.5in]{geometry}

\usepackage{fmtcount}             % for "\ordinal" macro
\fmtcountsetoptions{fmtord=level} % don't raise the ordinal indicator

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@makechapterhead}{\thechapter}{\ordinal{chapter}}{}{}
\makeatother

\begin{document}
\chapter{Title name}
\end{document}

附录:该fmtcount包不仅可以为英语文档提供序数,还可以为其他多种语言提供序数,甚至可以为给定语言中的方言形式提供序数。如果您不需要这种复杂性,您可以加载恩戈尔德包(大概带有选项normal)来代替,并在的第三个参数中替换\ordinal{chapter}为。\engord{chapter}\patchcmd

答案2

该类memoir(该类的超集book)提供序数和基数。请参阅文档第 18.14 节“数字格式”。

相关内容