平均能量损失

平均能量损失

我有下面的代码并且它可以工作,但不完全是我想要的方式。

\documentclass{report}
\usepackage[titles]{tocloft}
\usepackage{titlesec}
\renewcommand{\contentsname}{Table of contents}
\renewcommand{\cftchappresnum}{CHAPTER }
\renewcommand{\cftchapnumwidth}{0pt}
\renewcommand{\cftchapaftersnumb}{\vspace{3mm}\\}
\renewcommand{\cftchapfont}{\normalfont}
\renewcommand{\cftchappagefont}{\normalfont}
\renewcommand{\cftdotsep}{1}
\renewcommand{\cftchapleader}{\cftdotfill{\cftsecdotsep}}

\addtocontents{toc}{~\hfill  Page\par}
\titleformat{name=\chapter, numberless}[block]{\bfseries\large\filleft} {}{0em}{\MakeUppercase}[{\titlerule[1pt]}]
\titleformat{name=\chapter}[display]{\bfseries\huge\filleft} {\chaptername~\thechapter}{3ex}{\MakeUppercase}[{\titlerule[1pt]}]

\begin{document}
\tableofcontents

\chapter{FIRST CHAPTER}
\section{First Section}
\chapter{SECOND CHAPTER}
\chapter{THIRD CHAPTER}

\appendix
\chapter{ERASMUS POLICY}
\chapter{ERASMUS COUNTRY CODES}

\end{document}

输出如下

在此处输入图片描述

我需要帮助的是

附录以“CHAPTER”一词开头,而我希望它是“APPENDIX-A”,“APPENDIX-B”等等

答案1

您需要解决两个问题:

  1. 您的正文附录标题也错误。根据titlesec包中,您应该在第二个中使用\chaptertitlename而不是。 \chaptername\titleformat
    • 为什么你需要 \titleformat无论如何?你应该只保留一个。
  2. 现在修复了目录并进行了快速搜索这个答案。为了适应您的风格,您还可以使用\MakeUppercase

平均能量损失

\documentclass{report}
\usepackage[titles]{tocloft}
\usepackage{titlesec}
\renewcommand{\contentsname}{Table of contents}
% Don't use this:
%\renewcommand{\cftchappresnum}{CHAPTER }
% Use this:
\renewcommand{\cftchappresnum}{\MakeUppercase{\chaptername}\space}
% Modified from https://tex.stackexchange.com/a/56845/164314
\makeatletter
\g@addto@macro\appendix{%
  \addtocontents{toc}{%
    \protect\renewcommand{\protect\cftchappresnum}{\MakeUppercase{\appendixname}-}%
  }%
}
\makeatother
\renewcommand{\cftchapnumwidth}{0pt}
\renewcommand{\cftchapaftersnumb}{\vspace{3mm}\\}
\renewcommand{\cftchapfont}{\normalfont}
\renewcommand{\cftchappagefont}{\normalfont}
\renewcommand{\cftdotsep}{1}
\renewcommand{\cftchapleader}{\cftdotfill{\cftsecdotsep}}

\addtocontents{toc}{~\hfill  Page\par}
% You don't need to define title format twice
%\titleformat{name=\chapter, numberless}[block]{\bfseries\large\filleft} {}{0em}{\MakeUppercase}[{\titlerule[1pt]}]
%\titleformat{name=\chapter}[display]{\bfseries\huge\filleft} {\chaptername~\thechapter}{3ex}{\MakeUppercase}[{\titlerule[1pt]}]
% Use \chaptertitlename:
\titleformat{name=\chapter}[display]{\bfseries\huge\filleft} {\chaptertitlename~\thechapter}{3ex}{\MakeUppercase}[{\titlerule[1pt]}]

\begin{document}
\tableofcontents

\chapter{FIRST CHAPTER}
\section{First Section}
\chapter{SECOND CHAPTER}
\chapter{THIRD CHAPTER}

\appendix
\chapter{ERASMUS POLICY}
\chapter{ERASMUS COUNTRY CODES}

\end{document}

输出

目录:

在此处输入图片描述

正文附录:

在此处输入图片描述

相关内容