我试图让附录的标题名称出现在附录字母之前。但是,同时我正在使用 titlesec 来调整章节标题的外观。我发现了一个类似的问题,titlesec 和 appendix 的问题但是,答案并没有解决我的问题,因为它只改变了目录的外观。下面是 MWE:
\documentclass[a4paper, 12pt, english, leqno]{article}
\usepackage[compact]{titlesec}
\titlespacing\section{0pt}{12pt plus 4pt minus 2pt}{12pt plus 2pt minus 2pt}
\titlespacing\subsection{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}
\usepackage[title]{appendix}
\usepackage{titlesec}
\titleformat{\section}
{\normalfont\bfseries\center}{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\itshape}{\thesubsection}{1em}{}
\begin{document}
\section{A section}
\clearpage
\begin{appendices}
\section{first appendix}
\label{appendix:A}
\section{second appendix}
\label{appendix:B}
\end{document}
答案1
这就像你想要的那样吗?我对 做了一些更正\titleformat
,并加载了etoolbox
和\apptools
,它定义了布尔值\ifappendix
,在这种情况下非常有用。注意\appendixname
未出现在目录中。
\documentclass[a4paper, 12pt, english, leqno]{article}
\usepackage[compact]{titlesec}
\titlespacing\section{0pt}{12pt plus 4pt minus 2pt}{12pt plus 2pt minus 2pt}
\titlespacing\subsection{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}
\usepackage[title]{appendix}
\usepackage{etoolbox, apptools}
\AtBeginEnvironment{appendices}{\appendixtrue}
\usepackage{titlesec}
\titleformat{\section}[block]
{\normalfont\bfseries\filcenter}{\IfAppendix{\appendixname~}{\relax}\thesection\IfAppendix{: }{}}{1em}{}
\titleformat{\subsection}
{\normalfont\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\itshape}{\thesubsection}{1em}{}
\begin{document}
\section{A section}
\clearpage
\begin{appendices}
\section{first appendix}
\label{appendix:A}
If a woodchuck could chuck wood, would a woodchuck chuck wood?
\section{second appendix}
\label{appendix:B}
Blah blah blah.
\end{appendices}
\end{document}