2

I want to have appendix sections that are alphabetically numbered, within chapters:

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

trying this:

\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}

I get:

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

How can I fix the numbering?

  • You should say, how appendix section should be numbered. As A.1 or 1.1 or just without reference to the chapter they below too. – user31729 Apr 19 '16 at 6:03
  • @Christian the desired numbering is in the first part of my question. – dzeltzer Apr 19 '16 at 14:23
  • Alright, I have missed it, sorry. I will update – user31729 Apr 19 '16 at 14:28
  • 1
    See the update please! – user31729 Apr 19 '16 at 15:00
1

This works out of the box with the appendix package:

\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}

enter image description here

1

Multiple usages of the \appendix command is really designed in book.cls, since each time use of \appendix will reset both chapter and section counters and does also change the output of \thechapter from arabic numbers to \Alph - style.

I've decided to use \sectionappendix, that does not reset the chapter counter, but uses \Alph for \thechapter and restoring \thechapter at the beginning of each chapter automatically.

If hyperref is used some more action has to be done, i.e. redefine \theHsection etc.

\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}

Update

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.