如何使用 titlesec 打印章节基数而不是整数

如何使用 titlesec 打印章节基数而不是整数

我正在使用书籍环境并尝试将章节标题打印为“第一章”,而不是“第 1 章”。我搜索了“cardinal”和“chapter”,但没有找到任何与我想要的类似的内容。

问题是我正在使用 titlesec 包:

\documentclass[12pt, oneside,a4paper]{book} % The default font size and one-sided printing (no margin offsets)
\usepackage{graphics}
\graphicspath{ {images/} } % Specifies the directory where pictures are stored
\usepackage{multirow}
\usepackage{booktabs} % Horizontal rules in tables
\usepackage{url}
\usepackage[font=large]{subcaption}
\usepackage[font=large]{caption}
\usepackage{pbox}
\usepackage[usenames,dvipsnames]{xcolor,colortbl}
\definecolor{PaleGreen}{HTML}{E6E6E6}

\usepackage{manyfoot}       % NOTE: manyfoot and DeclareNewFootnote MUST be declared before the BibLatex package,
\DeclareNewFootnote{A}      % otherwise, you get an error about no room for a new counter
                            % Vanilla footnotes: use \footnoteB
\DeclareNewFootnote{B}

\usepackage[backend=bibtex,
            hyperref=true,
            url=false,
            isbn=false,
            backref=false,
            style=ieee,
            citereset=chapter,
            maxcitenames=3,
            maxbibnames=100,
            block=none]{biblatex}
%%%%%%%%%
% the command \sbc (short bracketed cite) defined below prints footnote citation with brackets
\newcommand{\sbc}[1]{\bfcite{#1}}           
%%%%%%%%%

\usepackage{rotating}

\usepackage{libertine}
\usepackage[T1]{fontenc}

\title{\ttitle} % Defines the thesis title - don't touch this

\usepackage{titlesec}
\newcommand{\hsp}{\hspace{10pt}}
\definecolor{chapterSepLine}{HTML}{41B6c4}
\definecolor{chapterNumColor}{HTML}{212121}
\newcommand{\blackTBar}{{\color{black}\titlerule[0.75pt]}}
\newcommand{\royalBlueTBar}{{\color{chapterSepLine}\titlerule[0.75pt]}}

%--------- Chapter heading format ---------
\titleformat{\chapter}
[hang] % shape
{\center\LARGE\usefont{T1}{bch}{b}{n}\selectfont}   % format
{{\color{chapterNumColor} {\chaptertitlename}~\thechapter}} % label
{0pt}   % sep
{\center\Huge\bfseries }    % before
[\hrule\vspace{1pt}\royalBlueTBar]  % after
\titlespacing*{\chapter}{0pt}{-35pt}{40pt} % \titlespacing[*]{<command>}{<left>}{<before-sep>}{<after-sep>}[<right-sep>]

%--------- Section heading format ---------
\titleformat{\section}[hang]{
    \usefont{T1}{bch}{b}{n}\selectfont} % bch for Bitstream Charter, and ppl for Palatino
    {} 
    {0em}
    {\hspace{-0.4pt}\Large \thesection\hspace{0.6em}}

%--------- Subsection heading format ---------
\titleformat{\subsection}[hang]{
    \usefont{T1}{bch}{b}{n}\selectfont} % bch for Bitstream Charter, and ppl for Palatino
    {} 
    {0em}
    {\hspace{-0.4pt}\large \thesubsection\hspace{0.6em}}

%--------- paragraph heading format ---------
\titleformat{\paragraph}[runin]{
    \usefont{T1}{bch}{b}{n}\selectfont} % bch for Bitstream Charter, and ppl for Palatino
    {} 
    {0em}
    {\hspace{-0.4pt}\large\hspace{0.6em}}


\usepackage[activate={true,nocompatibility},final,tracking=true,kerning=true,spacing=true,factor=1100,stretch=10,shrink=10]{microtype}

\renewcommand{\contentsname}{Table of Contents}

\usepackage{inconsolata}                % monofont only, which replaces the current mono (Libertine) font

\makeatletter

\patchcmd{\@makechapterhead}{%
  \huge\bfseries \@chapapp\space \thechapter}{ \huge\bfseries \@chapapp\space \Numberstring{chapter}}{}{}
\makeatother

\usepackage{fmtcount}%

\addbibresource{Bibliography.bib}

% ----------------------------------------------------------------
%   BEGIN DOCUMENT
% ----------------------------------------------------------------
\begin{document}
\chapter{Hello}
\end{document}

答案1

这是的快速解决方案book.cls,但这不会影响页面章节标记标题。

该类book使用命令\@makechapterhead通过 来设置章节标题\@chapapp\space \thechapter。使用补丁替换此命令

\@chapapp\space \Numberstring{chapter}

Chapter 1将会Chapter One等等

\Numberstring包中的宏fmtcount需要一个计数器名称并使用数字对应的口头表达。

\documentclass{book}

\usepackage{xpatch}

\makeatletter

\xpatchcmd{\@makechapterhead}{%
  \huge\bfseries \@chapapp\space \thechapter}{ \huge\bfseries \@chapapp\space \Numberstring{chapter}}{}{}
\makeatother

\usepackage{fmtcount}%

\begin{document}
\tableofcontents
\chapter{First}
\end{document}

在此处输入图片描述

笔记\xpatchcmd宏有两个最终参数,用于指示命令修补成功或失败...我省略了此代码;-)

新版本,带有来自 OP 的 MWE

章节格式必须从

{{\color{chapterNumColor} {\chaptertitlename}~\thechapter}} % label

对此

{{\color{chapterNumColor} {\chaptertitlename}~\Numberstring{chapter}}} % label



\documentclass[12pt, oneside,a4paper]{book} % The default font size and one-sided printing (no margin offsets)
\usepackage{graphics}
\graphicspath{ {images/} } % Specifies the directory where pictures are stored
\usepackage{multirow}
\usepackage{booktabs} % Horizontal rules in tables
\usepackage{url}
\usepackage[font=large]{subcaption}
\usepackage[font=large]{caption}
\usepackage{pbox}
\usepackage[usenames,dvipsnames]{xcolor,colortbl}
\definecolor{PaleGreen}{HTML}{E6E6E6}

\usepackage{manyfoot}       % NOTE: manyfoot and DeclareNewFootnote MUST be declared before the BibLatex package,
\DeclareNewFootnote{A}      % otherwise, you get an error about no room for a new counter
                            % Vanilla footnotes: use \footnoteB
\DeclareNewFootnote{B}

\usepackage[backend=bibtex,
            hyperref=true,
            url=false,
            isbn=false,
            backref=false,
            style=ieee,
            citereset=chapter,
            maxcitenames=3,
            maxbibnames=100,
            block=none]{biblatex}
%%%%%%%%%
% the command \sbc (short bracketed cite) defined below prints footnote citation with brackets
\newcommand{\sbc}[1]{\bfcite{#1}}           
%%%%%%%%%

\usepackage{rotating}

\usepackage{libertine}
\usepackage[T1]{fontenc}

\title{\ttitle} % Defines the thesis title - don't touch this
\usepackage{fmtcount}%

\usepackage{titlesec}
\newcommand{\hsp}{\hspace{10pt}}
\definecolor{chapterSepLine}{HTML}{41B6c4}
\definecolor{chapterNumColor}{HTML}{212121}
\newcommand{\blackTBar}{{\color{black}\titlerule[0.75pt]}}
\newcommand{\royalBlueTBar}{{\color{chapterSepLine}\titlerule[0.75pt]}}

%--------- Chapter heading format ---------
\titleformat{\chapter}
[hang] % shape
{\center\LARGE\usefont{T1}{bch}{b}{n}\selectfont}   % format
{{\color{chapterNumColor} {\chaptertitlename}~\Numberstring{chapter}}} % label
{0pt}   % sep
{\center\Huge\bfseries }    % before
[\hrule\vspace{1pt}\royalBlueTBar]  % after
\titlespacing*{\chapter}{0pt}{-35pt}{40pt} % \titlespacing[*]{<command>}{<left>}{<before-sep>}{<after-sep>}[<right-sep>]

%--------- Section heading format ---------
\titleformat{\section}[hang]{
    \usefont{T1}{bch}{b}{n}\selectfont} % bch for Bitstream Charter, and ppl for Palatino
    {} 
    {0em}
    {\hspace{-0.4pt}\Large \thesection\hspace{0.6em}}

%--------- Subsection heading format ---------
\titleformat{\subsection}[hang]{
    \usefont{T1}{bch}{b}{n}\selectfont} % bch for Bitstream Charter, and ppl for Palatino
    {} 
    {0em}
    {\hspace{-0.4pt}\large \thesubsection\hspace{0.6em}}

%--------- paragraph heading format ---------
\titleformat{\paragraph}[runin]{
    \usefont{T1}{bch}{b}{n}\selectfont} % bch for Bitstream Charter, and ppl for Palatino
    {} 
    {0em}
    {\hspace{-0.4pt}\large\hspace{0.6em}}


\usepackage[activate={true,nocompatibility},final,tracking=true,kerning=true,spacing=true,factor=1100,stretch=10,shrink=10]{microtype}

\renewcommand{\contentsname}{Table of Contents}

\usepackage{inconsolata}                % monofont only, which replaces the current mono (Libertine) font

\makeatletter

\patchcmd{\@makechapterhead}{%
  \huge\bfseries \@chapapp\space \thechapter}{ \huge\bfseries \@chapapp\space \Numberstring{chapter}}{}{}
\makeatother


\addbibresource{Bibliography.bib}

% ----------------------------------------------------------------
%   BEGIN DOCUMENT
% ----------------------------------------------------------------
\begin{document}
\chapter{Hello}
\end{document}

在此处输入图片描述

相关内容