由于重新定义附录命令,PDF 中出现嵌套书签

由于重新定义附录命令,PDF 中出现嵌套书签

我采用了@Mico的解决方案这里根据附录部分的节数来确定Appendix目录中的单数或复数形式。但是我发现该解决方案有一个副作用,即由hyperref包 in生成的 PDF 中的章节书签pdfLatex是嵌套的。

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

在此处输入图片描述

答案1

使用该bookmark软件包可以修复此问题。只需添加\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}

在此处输入图片描述

相关内容