1

I adopted @Mico 's solution in here to determine the singular or plural form of Appendix in the ToC based on the number of sections in the appendix part. However, I find that the solution has a side effect that the bookmarks of chapters in the PDF which are produced by hyperref package in pdfLatex are nested.

\documentclass[11pt, a4paper, twoside]{book}
\RequirePackage[title,titletoc]{appendix}

\usepackage{ifthen}
\makeatletter
%% For source of "@seccntformat" command, see book "The LaTeX Companion"
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\ \ }%  default
   {\csname #1@cntformat\endcsname}}%    enable individual control
%% Individual control: '\section@cntformat'
\newcommand{\section@cntformat}{\thechapter.\thesection\ \ }

% Macros to redefine numbering of appendix sections
\newcommand{\appname}{} % dummy definition 
\newcommand{\appsecnumbering}[1][0]{%
    \ifthenelse{#1=1}{\renewcommand\appname{Appendix}}
                     {\renewcommand\appname{Appendices}}
    \setcounter{section}{0}
    \renewcommand\thesection{\thechapter.\Alph{section}}
    \renewcommand{\section@cntformat}{\appendixname~\thesection\ \ }
    \addtocontents{toc}{\medskip\protect{\mdseries\appname\par}}}
\newcommand\normalsecnumbering{%
    \renewcommand{\thesection}{\thechapter.\arabic{section}}
    \renewcommand{\section@cntformat}{\thesection\ \ }}
\let\origchapter\chapter
\renewcommand\chapter{\normalsecnumbering % first, reset numbering style
    \origchapter} % second, execute the original \chapter command
\makeatother


\usepackage[ pdftex, plainpages = false, pdfpagelabels, 
pdfpagelayout = useoutlines,
bookmarks,
bookmarksopen = true,
bookmarksnumbered = true,
breaklinks = true,
linktocpage,
%pagebackref,
colorlinks = true,
linkcolor = blue,
urlcolor  = blue,
citecolor = blue,
anchorcolor = green,
hyperindex = true,
pdfpagelabels,
hyperfigures
]{hyperref}


\begin{document}
\tableofcontents


\chapter{First chapter}
\section{A sections}
\subsection{A subsection}
\appsecnumbering[1]
\section{First appendix}


\chapter{Second chapter}
\section{A section}

% \begin{subappendices}
\appsecnumbering[2]
\section{First appendix}
\section{Second appendix}
% \end{subappendices}

\end{document}

enter image description here

1

Using the bookmark package will fix the issue. Just add \usepackage{bookmark}:

\documentclass[11pt, a4paper, twoside]{book}
\RequirePackage[title,titletoc]{appendix}

\usepackage{ifthen}
\makeatletter
%% For source of "@seccntformat" command, see book "The LaTeX Companion"
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\ \ }%  default
   {\csname #1@cntformat\endcsname}}%    enable individual control
%% Individual control: '\section@cntformat'
\newcommand{\section@cntformat}{\thechapter.\thesection\ \ }

% Macros to redefine numbering of appendix sections
\newcommand{\appname}{} % dummy definition
\newcommand{\appsecnumbering}[1][0]{%
    \ifthenelse{#1=1}{\renewcommand\appname{Appendix}}
                     {\renewcommand\appname{Appendices}}
    \setcounter{section}{0}
    \renewcommand\thesection{\thechapter.\Alph{section}}
    \renewcommand{\section@cntformat}{\appendixname~\thesection\ \ }
    \addtocontents{toc}{\medskip\protect{\mdseries\appname\par}}}
\newcommand\normalsecnumbering{%
    \renewcommand{\thesection}{\thechapter.\arabic{section}}
    \renewcommand{\section@cntformat}{\thesection\ \ }}
\let\origchapter\chapter
\renewcommand\chapter{\normalsecnumbering % first, reset numbering style
    \origchapter} % second, execute the original \chapter command
\makeatother


\usepackage[ pdftex, plainpages = false, pdfpagelabels,
pdfpagelayout = useoutlines,
bookmarks,
bookmarksopen = true,
bookmarksnumbered = true,
breaklinks = true,
linktocpage,
%pagebackref,
colorlinks = true,
linkcolor = blue,
urlcolor  = blue,
citecolor = blue,
anchorcolor = green,
hyperindex = true,
pdfpagelabels,
hyperfigures
]{hyperref}
\usepackage{bookmark}

\begin{document}
\tableofcontents


\chapter{First chapter}
\section{A sections}
\subsection{A subsection}
\appsecnumbering[1]
\section{First appendix}


\chapter{Second chapter}
\section{A section}

% \begin{subappendices}
\appsecnumbering[2]
\section{First appendix}
\section{Second appendix}
% \end{subappendices}

\end{document}

enter image description here

| improve this answer | |
  • 1
    Fantastic answer! Though not quite sure what happened. The problem only happens when the chapter has several subsections. – WZhao Sep 13 '19 at 14:47
  • Hello, I find that the hyperlink and bookmarks of appendix are wrong. Could you take a look at this new question? – WZhao Sep 16 '19 at 14:52

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.