![附录章节命名 - titlesec/appendix 冲突](https://linux22.com/image/383415/%E9%99%84%E5%BD%95%E7%AB%A0%E8%8A%82%E5%91%BD%E5%90%8D%20-%20titlesec%2Fappendix%20%E5%86%B2%E7%AA%81.png)
我正在使用 titlesec 将格式应用于章节和节标题。当我向文档添加附录时,章节名称显示为“第 A 章”,而它应该显示为“附录 A”
运行\renewcommand
after\begin{appendices}
似乎没有效果。我相信titlesec
和之间存在冲突appendix
,但我不确定如何解决它。
如何重新定义附录章节名称?
\documentclass[11pt,a4paper]{report}
\setlength{\headheight}{13.6pt}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{appendix}
%Pagestyle setup
\pagestyle{fancyplain}
\fancyhf{}
\fancyfoot[R]{\thepage}
\fancyhead[R]{\fancyplain{}{\nouppercase\leftmark}}
\renewcommand{\headrulewidth}{0pt}
\usepackage{xpatch}
\xpatchcmd\chaptermark{. }{\ --}{}{\PatchFailed}
%Title formatting
\titleformat
{\chapter}[display]
{\bfseries\LARGE}{Chapter \thechapter}{2ex}
{
\vspace{-0.5ex}
\rule{\textwidth}{0.4pt}
\centering
}
[
\vspace{-1.5ex}
\rule{\textwidth}{0.4pt}
\vspace{-4ex}
]
\begin{document}
\cleardoublepage
\pagenumbering{roman}
\chapter*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}
\pagestyle{plain}
\lipsum
\appendixtitleon
\appendixtitletocon
\tableofcontents
\cleardoublepage
\pagenumbering{arabic}
\pagestyle{fancy}
\chapter{Introduction}
\lipsum
\clearpage
\pagestyle{plain}
\begin{appendices}
\renewcommand\chaptername{Appendix} %Has no effect
\renewcommand\appendixname{Appendix} %Also has no effect
\renewcommand\chaptertitlename{Appendix} %From titlesec documentation. Again, no effect
\chapter{The first appendix}
\lipsum{}
\end{appendices}
\end{document}
答案1
如果您想要\renewcommand\chaptertitlename{...}
产生效果,您可能希望在自定义章节格式的定义中构建它。
\documentclass[11pt,a4paper]{report}
\setlength{\headheight}{13.6pt}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{appendix}
%Pagestyle setup
\pagestyle{fancyplain}
\fancyhf{}
\fancyfoot[R]{\thepage}
\fancyhead[R]{\fancyplain{}{\nouppercase\leftmark}}
\renewcommand{\headrulewidth}{0pt}
\usepackage{xpatch}
\xpatchcmd\chaptermark{. }{\ --}{}{\PatchFailed}
\renewcommand\chaptertitlename{Chapter}
%Title formatting
\titleformat
{\chapter}[display]
{\bfseries\LARGE}{\chaptertitlename\ \thechapter}{2ex}
{
\vspace{-0.5ex}
\rule{\textwidth}{0.4pt}
\centering
}
[
\vspace{-1.5ex}
\rule{\textwidth}{0.4pt}
\vspace{-4ex}
]
\begin{document}
\cleardoublepage
\pagenumbering{roman}
\chapter*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}
\pagestyle{plain}
\lipsum
\appendixtitleon
\appendixtitletocon
\tableofcontents
\cleardoublepage
\pagenumbering{arabic}
\pagestyle{fancy}
\chapter{Introduction}
\lipsum
\clearpage
\pagestyle{plain}
\begin{appendices}
\renewcommand\chaptertitlename{Appendix} %From titlesec documentation. Again, no effect
\chapter{The first appendix}
\lipsum{}
\end{appendices}
\end{document}