如何修复编号?
这是一个最简单的例子。我认为这个问题是不言自明的。
\documentclass{report}
\usepackage[explicit]{titlesec}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@makechapterhead}% <cmd>
{\thechapter}% <search>
{\expandafter\ifx\@chapapp\appendixname\else\ifnum\value{chapter}<10
0\fi\fi\thechapter}% <replace>
{}{}% <success><failure>
\makeatother
\makeatletter
\renewcommand\thesection{}
\renewcommand\thesubsection{\@arabic\c@chapter.\@arabic\c@subsection}
\makeatother
\begin{document}
\chapter{First Chapter}
\section{First Section}
\subsection{Subsection 1.1}
\subsection{Subsection 1.2}
\section{Second Section}
\subsection{Subsection 1.3}
\appendix
\setcounter{chapter}{2}
\chapter{Appendix C}
\section{First Section}
\subsection{Subsection C.1}
\end{document}
以防万一:“第 1.3 小节”应编号为 1.3,“第 C.1 小节”应编号为 C.1。
答案1
看起来编号方案有点奇怪,但我将小节添加到章节的重置列表中,并将其从章节中删除。
\documentclass{report}
\usepackage[explicit]{titlesec}
\usepackage{etoolbox,remreset}
\makeatletter
\patchcmd{\@makechapterhead}% <cmd>
{\thechapter}% <search>
{\expandafter\ifx\@chapapp\appendixname\else\ifnum\value{chapter}<10
0\fi\fi\thechapter}% <replace>
{}{}% <success><failure>
\makeatother
\makeatletter
\@removefromreset{subsection}{section}
\@addtoreset{subsection}{chapter}
\renewcommand\thesection{}
\renewcommand\thesubsection{\thechapter.\@arabic\c@subsection}
\makeatother
\begin{document}
\chapter{First Chapter}
\section{First Section}
\subsection{Subsection 1.1}
\subsection{Subsection 1.2}
\section{Second Section}
\subsection{Subsection 1.3}
\appendix
\renewcommand\thechapter{\Alph{chapter}}
\setcounter{chapter}{2}
\chapter{Appendix C}
\section{First Section}
\subsection{Subsection C.1}
\end{document}