附录章节命名 - titlesec/appendix 冲突

附录章节命名 - titlesec/appendix 冲突

我正在使用 titlesec 将格式应用于章节和节标题。当我向文档添加附录时,章节名称显示为“第 A 章”,而它应该显示为“附录 A”

在此处输入图片描述

运行\renewcommandafter\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}

相关内容