第一种方法

第一种方法

我使用appendix包创建附录,但也使用etoolbox命令自定义它们。目录页码指向附录部分的正确页面,但超链接跳转到错误的位置。

\documentclass[11pt,a4paper,oneside]{book}

\usepackage[x11names]{xcolor}
\usepackage{caption}
\usepackage{etoolbox}
\usepackage{graphicx}
\usepackage{hyperref}
\hypersetup{linkcolor=DodgerBlue3, colorlinks=true}
\usepackage{tocloft}
\usepackage{appendix}

    % customizing appendices

        % renew the tags of figures, tables and equations
        \newcounter{appendix}
        \AtBeginEnvironment{appendices}{\renewcommand{\thefigure}{\Alph{appendix}.\arabic{figure}.}}
        \AtBeginEnvironment{appendices}{\renewcommand{\thetable}{\Alph{appendix}.\arabic{table}.}}
        \AtBeginEnvironment{appendices}{\renewcommand{\theequation}{\Alph{appendix}.\arabic{equation}}}
        \AtBeginEnvironment{appendices}{\renewcommand{\chaptername}{APPENDIX}}
        \AtBeginEnvironment{appendices}{\renewcommand{\thesection}{\arabic{appendix}.\arabic{section}.}}

        % Define new way to add appendices to the TOC
        \newcommand{\appendixtitle}{}
        \newcommand{\appendixtitleFull}{\chaptername\space\Alph{appendix}.\space\appendixtitle}
        \AtBeginEnvironment{appendices}{
            \preto{\chapter}{
                \clearpage
                \addtocounter{appendix}{1}
                \setcounter{section}{0}
                \setcounter{figure}{0}
                \setcounter{equation}{0}
                \phantomsection \addcontentsline{toc}{chapter}{\appendixtitleFull}
                        }
                                    }


\newcommand{\sampleEquationFloats}{

\begin{figure}
    \includegraphics[]{example-image-a}
    \caption{Figure Caption}
\end{figure}

\begin{equation}
    E = m c^{2}
\end{equation}

\begin{table}
    \caption{Table Caption}
    \centering
    \begin{tabular}{|c |c|}
        \hline
        Column & Column
        \\
        \hline
    \end{tabular}
\end{table}

}



\begin{document}

\tableofcontents

\begin{appendices}

    \renewcommand{\appendixtitle}{My Title}
    \chapter*{\appendixtitleFull}

        \sampleEquationFloats

        \section{One Section}

        \section{Another Section}

    \renewcommand{\appendixtitle}{My Title}
    \chapter*{\appendixtitleFull}

        \sampleEquationFloats

        \section{One Section}

        \section{Another Section}

    \renewcommand{\appendixtitle}{My Title}
    \chapter*{\appendixtitleFull}

        \sampleEquationFloats

        \section{One Section}

        \section{Another Section}

\end{appendices}

\end{document} 

答案1

这里有一个解决方案目录 各部分的章节链接指向前几部分的章节 。使用类似的方法,我们重新定义\theHsection\theHsubsection如下

\renewcommand*{\theHsection}{\thesection}
\renewcommand*{\theHsubsection}{\thesubsection}

完整代码

\documentclass[11pt,a4paper,oneside]{book}

\usepackage[x11names]{xcolor}
\usepackage{caption}
\usepackage{etoolbox}
\usepackage{graphicx}
\usepackage{hyperref}
\hypersetup{linkcolor=DodgerBlue3, colorlinks=true}
\usepackage{tocloft}
\usepackage{appendix}

    % customizing appendices

        % rennew the tags of figures, tables and equations
        \AtBeginEnvironment{appendices}{\renewcommand{\thefigure}{\Alph{appendix}.\arabic{figure}.}}
        \AtBeginEnvironment{appendices}{\renewcommand{\thetable}{\Alph{appendix}.\arabic{table}.}}
        \AtBeginEnvironment{appendices}{\renewcommand{\theequation}{\Alph{appendix}.\arabic{equation}}}
        \AtBeginEnvironment{appendices}{\renewcommand{\chaptername}{APPENDIX}}
        \AtBeginEnvironment{appendices}{\renewcommand{\thesection}{\arabic{appendix}.\arabic{section}.}}

        % Define new way to add appendices to the TOC
        \newcounter{appendix}
        \newcommand{\appendixtitle}{}
        \newcommand{\appendixtitleFull}{\chaptername\space\Alph{appendix}.\space\appendixtitle}
        \AtBeginEnvironment{appendices}{
            \preto{\chapter}{
                % Clear the page (to guarantee referring to the correct page)
                \clearpage
                % Add to appendix counter
                \addtocounter{appendix}{1}
                % Redefine hyperlinks for sections and subsections
                \renewcommand*{\theHsection}{\thesection}
                \renewcommand*{\theHsubsection}{\thesubsection}
                % Reset counters
                \setcounter{section}{0}
                \setcounter{subsection}{0}
                \setcounter{figure}{0}
                \setcounter{table}{0}
                \setcounter{equation}{0}
                % Insert an appendix entry in the TOC
                \phantomsection \addcontentsline{toc}{chapter}{\appendixtitleFull}
                        }
                                    }


\newcommand{\sampleEquationFloats}{

\begin{figure}
    \includegraphics[]{example-image-a}
    \caption{Figure Caption}
\end{figure}

\begin{equation}
    E = m c^{2}
\end{equation}

\begin{table}
    \caption{Table Caption}
    \centering
    \begin{tabular}{|c |c|}
        \hline
        Column & Column
        \\
        \hline
    \end{tabular}
\end{table}

}



\begin{document}

\tableofcontents

\begin{appendices}

    \renewcommand{\appendixtitle}{My Title}
    \chapter*{\appendixtitleFull}

        \sampleEquationFloats

        \section{One Section}

        \section{Another Section}

    \renewcommand{\appendixtitle}{My Title}
    \chapter*{\appendixtitleFull}

        \sampleEquationFloats

        \section{One Section}

        \section{Another Section}

    \renewcommand{\appendixtitle}{My Title}
    \chapter*{\appendixtitleFull}

        \sampleEquationFloats

        \section{One Section}

        \section{Another Section}

\end{appendices}

\end{document} 

答案2

如果您简化设置并利用caption包的功能(无论如何您都会加载它),并且如果您更改\addtocounter{appendix}{1}\refstepcounter{appendix},则超目标的位置似乎完全正确。

附言:为了让目录、图片列表和表格列表看起来像一堆华丽的圣诞树,我会在说明linktocpage=true中添加选项\hypersetup。这样,页码而不是目录条目就会变成超链接。

附录,在收到 OP 的后续评论后插入:使用这里建议的设置,只需提供以下三个说明(最好在加载包后立即提供),即可在目录、图表和表格列表中的章节、图表和表格编号后显示“点”(“句号”,又名“句号”)tocloft

\renewcommand\cftsecaftersnum{.}
\renewcommand\cftfigaftersnum{.}
\renewcommand\cfttabaftersnum{.}

在此处输入图片描述

\documentclass[11pt,a4paper,oneside]{book}
\usepackage[x11names]{xcolor}
\usepackage{caption,etoolbox,graphicx,appendix}

\usepackage{tocloft} % influence appearance of ToC, LoF, and LoT
\renewcommand\cftsecaftersnum{.}
\renewcommand\cftfigaftersnum{.}
\renewcommand\cfttabaftersnum{.}

\usepackage{hyperref}
\hypersetup{linkcolor=DodgerBlue3, colorlinks, linktocpage}

% Customize tags of sections, figures, tables and equations in 'appendices' env.
\newcounter{appendix}
\renewcommand{\theappendix}{\Alph{appendix}}
\newcommand{\appendixtitle}{}
\newcommand{\appendixtitleFull}{%
  \chaptername\space\Alph{appendix}.\quad\appendixtitle}
\AtBeginEnvironment{appendices}{%
  \renewcommand{\chaptername}{APPENDIX}
  \captionsetup{labelsep=period}
  \counterwithin{figure}{appendix}
  \counterwithin{table}{appendix}
  \counterwithin{equation}{appendix}
  \counterwithin{section}{appendix}  
  \preto{\chapter}{%
    \clearpage
    \refstepcounter{appendix}
    \phantomsection 
    \addcontentsline{toc}{chapter}{\appendixtitleFull}%
  }
}

\newcommand{\sampleEquationFloatsSections}{%
  \begin{figure}[h!]
    \centering
    \includegraphics[]{example-image-a}
    \caption{Figure Caption}
  \end{figure}
  \begin{equation} E = mc^2 \end{equation}
  \begin{table}[h!]
    \caption{Table Caption}
    \centering
    \begin{tabular}{|c|c|}
        \hline Column & Column \\ \hline
    \end{tabular}
  \end{table}
  \section{A Section}
  \section{Another Section}
}

\begin{document}
%% Generate the ToC, LoF, and LoT:
\tableofcontents
\listoffigures
\listoftables

%% Generate three sample appendices, each with 
%% an equation, table, figure, and two sections
\begin{appendices}
    \renewcommand{\appendixtitle}{My Title A}
    \chapter*{\appendixtitleFull}
    \sampleEquationFloatsSections

    \renewcommand{\appendixtitle}{My Title B}
    \chapter*{\appendixtitleFull}
    \sampleEquationFloatsSections

    \renewcommand{\appendixtitle}{My Title C}
    \chapter*{\appendixtitleFull}
    \sampleEquationFloatsSections
\end{appendices}

\end{document} 

答案3

第一种方法

您需要声明您的section计数器从属于计数器(通常,它在类中appendix从属于)。使用以下命令执行此操作:chapterbook

\@addtoreset{section}{appendix}

已经\AtBeginEnvironment{appendices}{...}足够了,因为hyperref已经加载了(参见下属柜台hyperref手册中)。这将给出以下代码:

\documentclass[11pt,a4paper,oneside]{book}

\usepackage[x11names]{xcolor}
\usepackage{caption}
\usepackage{etoolbox}
\usepackage{graphicx}
\usepackage{hyperref}
\hypersetup{linkcolor=DodgerBlue3, colorlinks=true}
\usepackage{tocloft}
\usepackage{appendix}

    % customizing appendices

\makeatletter

        % renew the tags of figures, tables and equations
        \newcounter{appendix}
        \AtBeginEnvironment{appendices}{\renewcommand{\thefigure}{\Alph{appendix}.\arabic{figure}.}}
        \AtBeginEnvironment{appendices}{\renewcommand{\thetable}{\Alph{appendix}.\arabic{table}.}}
        \AtBeginEnvironment{appendices}{\renewcommand{\theequation}{\Alph{appendix}.\arabic{equation}}}
        \AtBeginEnvironment{appendices}{\renewcommand{\chaptername}{APPENDIX}}
        \AtBeginEnvironment{appendices}{\renewcommand{\thesection}{\arabic{appendix}.\arabic{section}.}}

        % Define new way to add appendices to the TOC
        \newcommand{\appendixtitle}{}
        \newcommand{\appendixtitleFull}{\chaptername\space\Alph{appendix}.\space\appendixtitle}
        \AtBeginEnvironment{appendices}{
            \preto{\chapter}{
                \clearpage
                \addtocounter{appendix}{1}
                \setcounter{section}{0}
                \@addtoreset{section}{appendix}
                \setcounter{figure}{0}
                \setcounter{equation}{0}
                \phantomsection
                \addcontentsline{toc}{chapter}{\appendixtitleFull}
                        }
                                    }
\makeatother

\newcommand{\sampleEquationFloats}{

\begin{figure}
    \includegraphics[]{example-image-a}
    \caption{Figure Caption}
\end{figure}

\begin{equation}
    E = m c^{2}
\end{equation}

\begin{table}
    \caption{Table Caption}
    \centering
    \begin{tabular}{|c |c|}
        \hline
        Column & Column
        \\
        \hline
    \end{tabular}
\end{table}

}



\begin{document}

\tableofcontents

\begin{appendices}

    \renewcommand{\appendixtitle}{My Title}
    \chapter*{\appendixtitleFull}

        \sampleEquationFloats

        \section{One Section}

        \section{Another Section}

    \renewcommand{\appendixtitle}{My Title}
    \chapter*{\appendixtitleFull}

        \sampleEquationFloats

        \section{One Section}

        \section{Another Section}

    \renewcommand{\appendixtitle}{My Title}
    \chapter*{\appendixtitleFull}

        \sampleEquationFloats

        \section{One Section}

        \section{Another Section}

\end{appendices}

\end{document}

第二种方法

手册中提到的另一种技术hyperref(第节下属柜台) 也这里包括重新定义\theHsection

\renewcommand*{\theHsection}{Appendix.\theHappendix.\thesection}

例如,在钩子的开头\AtBeginEnvironment{appendices}{...}。这确保hyperref在准备超链接时看到节计数器的唯一值。

答案4

我必须补充一下

\phantomsection
\addcontentsline{toc}{chapter}{Some new chapter}%

通过单击,我可以转到我想要从目录中进入的每个部分。

我还必须补充\providecommand\phantomsection{}一下我的序言。

说明: \providecommand\phantomsection{}定义锚点并\phantomsection锚定该部分,以便从目录单击即可跳转到该部分。

相关内容