章节中的附录部分,按字母顺序编号

章节中的附录部分,按字母顺序编号

我想要按字母顺序编号的章节附录部分:

Chapter 1
First Chapter
1.1 First Chapter Section
1.A First Chapter Appendix
1.B Second Chapter Appendix

Chapter 2
Second Chapter
2.1 Second Chapter
2.A First Chapter Section

尝试这个:

\documentclass{book}
\begin{document}
\chapter{First Chapter}
  \section{First Chapter Section}
  \appendix
  \section{First Chapter Appendix}
  \section{Second Chapter Appendix}

\chapter{Second Chapter}
  \section{Second Chapter Section}
  \appendix
  \section{Second Chapter Appendix}
\end{document}

我得到:

Chapter 1
First Chapter
1.1 First Chapter Section
.1 First Chapter Appendix
.2 Second Chapter Appendix

Appendix A
Second Chapter
A.1 Second Chapter
.1 First Chapter Section

我该如何修复编号?

答案1

该软件包开箱即可使用appendix

\documentclass{book}
\usepackage{appendix}

\begin{document}

\frontmatter

\tableofcontents

\mainmatter

\chapter{First Chapter}

\section{First Chapter Section}

\begin{subappendices}

\section{First Chapter Appendix}

\section{Second Chapter Appendix}

\end{subappendices}


\chapter{Second Chapter}

\section{Second Chapter Section}

\begin{subappendices}

\section{Second Chapter Appendix}

\end{subappendices}

\end{document}

在此处输入图片描述

答案2

该命令的多种用法\appendix确实是在设计的book.cls,因为每次使用\appendix都会重置chaptersection计数器,并且也会将的输出\thechapter从阿拉伯数字更改为\Alph- 样式。

我决定使用\sectionappendix,它不会重置章节计数器,而是使用\Alph和在每章开始时自动\thechapter恢复。\thechapter

如果hyperref使用,则必须采取更多措施,即重新定义\theHsection等。

\documentclass{book}

\usepackage{xpatch}

\makeatletter

\xpretocmd{\chapter}{%
  \renewcommand{\thechapter}{\@arabic\c@chapter}}{}{}

\newcommand\sectionappendix{\par
  \setcounter{section}{0}%
  \gdef\@chapapp{\appendixname}%
  \gdef\thechapter{\@Alph\c@chapter}}
\makeatother

\begin{document}
\chapter{First Chapter}
\section{First Chapter Section}
\sectionappendix
\section{First Chapter Appendix}
\section{Second Chapter Appendix}

\chapter{Second Chapter}
\section{Second Chapter Section}
\sectionappendix
\section{Second Chapter Appendix}
\end{document}

更新

\documentclass{book}

\usepackage{xpatch}

\newif\ifappendixchapter


\makeatletter

\let\latex@@thechapter\thechapter
\let\latex@@thesection\thesection

\xpretocmd{\chapter}{%
  % Restore the original settings for \thechapter and \thesection
  \ifappendixchapter
  \else
  \let\thechapter\latex@@thechapter
  \let\thesection\latex@@thesection
  \fi
}{}{}

\xpretocmd{\appendix}{%
  \let\thechapter\latex@@thechapter % Restore first
  \let\thesection\latex@@thesection % Restore first
  \appendixchaptertrue
}{}{}


\newcommand\sectionappendix{\par
  \setcounter{section}{0}%
  \gdef\thesection{\thechapter.\@Alph\c@section}}
\makeatother

\begin{document}
\chapter{First Chapter}
\section{First Chapter Section}
\sectionappendix
\section{First Chapter Appendix}
\section{Second Chapter Appendix}

\chapter{Second Chapter}
\section{Second Chapter Section}
\sectionappendix
\section{Second Chapter Appendix}

% Real appendix

\appendix

\chapter{First Appendix chapter}
\section{First section in first appendix chapter}
\end{document}

相关内容