![你能帮我修改这个 tex 文件吗?“关于章节格式”](https://linux22.com/image/430584/%E4%BD%A0%E8%83%BD%E5%B8%AE%E6%88%91%E4%BF%AE%E6%94%B9%E8%BF%99%E4%B8%AA%20tex%20%E6%96%87%E4%BB%B6%E5%90%97%EF%BC%9F%E2%80%9C%E5%85%B3%E4%BA%8E%E7%AB%A0%E8%8A%82%E6%A0%BC%E5%BC%8F%E2%80%9D.png)
\documentclass[12pt,a4paper]{report}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{fontspec}
\usepackage{pgfplots,tikz,enumerate,array,fancyhdr,enumitem,fancybox,graphicx,amsfonts,amsmath,amssymb,amsthm,mathrsfs}
\usepackage{titlesec}
\usepackage[arabic]{minitoc}
\usepackage{fancybox}
%========================================================
% languages & fonts===========================================
\usepackage[numbers]{natbib}
\usepackage{polyglossia}
\setdefaultlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
\setcounter{minitocdepth}{1}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.2]{Amiri}
\newfontfamily\arabicfontsf[Script=Arabic,Scale=1.2]{Andalus}
%%
%=========================================================
\addto\captionsarabic{%
\renewcommand{\chaptername}{\sffamily الفصل}%
}
\addto\captionsarabic{\renewcommand{\chaptername}{\sffamily الفصل }}
%===============================================================
\pagestyle{fancy}
\parindent=0pt
\newcommand\words[1]{\expandafter\xwords\csname c@#1\endcsname}
\def\xwords#1{\ifcase#1\or الأول
\or الثاني
\or الثالث
\or الرابع
\or الخامس
\else
I need more words\fi}
%=======================================
\makeatletter
\patchcmd{\@makechapterhead}{\thechapter}{\words{chapter}}{}{}
\makeatother
%=============================================
\titleformat{\chapter}
{\bfseries\large}
{}
{0pt}
{\titlerule{3pt}~\raisebox{-3.5pt}
{\sc{\chaptername}~
\thechapter}~\Huge\titlerule{3pt}\\
\vspace{1.05cm}\titlerule{}\\
\filcenter #1\\
\vspace{1.25cm}\titlerule}
\begin{document}
\chapter{الرياضيات}
\end{document}
答案1
这是一个解决方案。
首先你需要加载标题带有选项的包明确的IE \usepackage[explicit]{titlesec}
。
第二,该命令\titlerule
有一个选修的参数,所以需要输入\titlerule[3pt]
。
对于问题,请添加评论。应该使用numberless
变体来定义章节格式或类似格式。
\titleformat{name=\chapter}...
用于编号章节。
\titleformat{name=\chapter, numberless}...
对于未编号的章节。
\documentclass[12pt,a4paper]{report}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{fontspec}
\usepackage{pgfplots,tikz,enumerate,array,fancyhdr,enumitem,fancybox,graphicx,amsfonts,amsmath,amssymb,amsthm,mathrsfs}
\usepackage[explicit]{titlesec}
\usepackage[arabic]{minitoc}
\usepackage{fancybox}
%========================================================
% languages & fonts===========================================
\usepackage[numbers]{natbib}
\usepackage{polyglossia}
\setdefaultlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
\setcounter{minitocdepth}{1}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.2]{Amiri}
\newfontfamily\arabicfontsf[Script=Arabic,Scale=1.2]{Andalus}
%%
%=========================================================
\addto\captionsarabic{%
\renewcommand{\chaptername}{\sffamily الفصل}%
}
\addto\captionsarabic{\renewcommand{\chaptername}{\sffamily الفصل }}
%===============================================================
\pagestyle{fancy}
\parindent=0pt
\newcommand\words[1]{\expandafter\xwords\csname c@#1\endcsname}
\def\xwords#1{\ifcase#1\or الأول
\or الثاني
\or الثالث
\or الرابع
\or الخامس
\else
I need more words\fi}
%=======================================
\makeatletter
\patchcmd{\@makechapterhead}{\thechapter}{\words{chapter}}{}{}
\makeatother
%=============================================
\titleformat{name=\chapter}
{\bfseries\large}
{}
{0pt}
{\titlerule[3pt]~\raisebox{-3.5pt}
{\sc{\chaptername}~
\thechapter}~\Huge\titlerule[3pt]\\
\vspace{1.05cm}\titlerule\\
\filcenter #1\\
\vspace{1.25cm}\titlerule}
\titleformat{name=\chapter, numberless}
{\bfseries\large}
{}
{0pt}
{%
%\titlerule[3pt]\\ %comment or uncomment this
\Huge
%\titlerule[3pt]\\ %comment or uncomment this
\vspace{1.05cm}\titlerule\\
\filcenter #1\\
\vspace{1.25cm}\titlerule}
\begin{document}
\tableofcontents
\chapter{الرياضيات}
\end{document}