由于重新定义附录命令导致附录链接错误

由于重新定义附录命令导致附录链接错误

我采用了@Mico的解决方案这里Appendix根据附录部分的节数来确定目录中的单数或复数形式。它非常适合此目的。

但是,我发现该解决方案有一个副作用,即附录的超链接是错误的,并且 PDF 中的书签也是错误的。

请参阅以下 MWE。Appendix 1.A错误地引用了第 1.1 节。Appendix 2.A链接到第 2.1 节的也存在同样的问题。但引用Appendix 2.B是正确的。

如果有其他方法可以改变Appendix目录中的单数或复数形式,我也很乐意接受。

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

% solution in https://tex.stackexchange.com/a/47011/87806
\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}
\lipsum[1]
\subsection{A subsection}

See Appendix \ref{app:first}. % Wrongly referred to section 1.1

\lipsum[2-4]

% \begin{subappendices}
\appsecnumbering[1]
\section{First appendix} \label{app:first}
\lipsum[2]
% \end{subappendices}


\chapter{Second chapter}
\section{A section}
See Appendix \ref{app:first2}. % Wrongly referred to section 2.1

See Appendix \ref{app:second}. % Correct

\lipsum[2-4]

% \begin{subappendices}
\appsecnumbering[2]
\section{First appendix} \label{app:first2}
\lipsum[2-4]
\section{Second appendix} \label{app:second}
\lipsum[2-4]
% \end{subappendices}

\end{document}

相关内容