我在这里提供一个 MWE:
\documentclass{article}
\usepackage{titletoc}
\usepackage[colorlinks=true
,urlcolor=blue
,anchorcolor=blue
,citecolor=blue
,filecolor=blue
,linkcolor=blue
,menucolor=blue
,linktocpage=true
,bookmarks=true
,unicode=true
,pdfa=true
]{hyperref}
\titlecontents{section}%
[9mm]
{}
{\contentslabel[%
\hyperlink{%
section.\thecontentslabel
}{%
\thecontentslabel.%
}]%
{7mm}}
{\hspace*{-7mm}}
{\hfill\contentspage}
{}
\titlecontents{subsection}%
[20mm]
{}
{\contentslabel[
\hyperlink{%
subsection.\thecontentslabel%
}{%
\thecontentslabel%
}]%
{12mm}}%
{\hspace*{-12mm}}
{\hfill\contentspage}
{}
\begin{document}
\tableofcontents
\section{First}
\subsection{FF}
\subsection{FS}
\section{Second}
\subsection{SF}
\subsection{FF}
\appendix
\section{App1}
\subsection{App1F}
\subsection{App1S}
\end{document}
我不得不说目录是确切地就像我想要的那样,但有一个奇怪的问题:虽然所有“1。”“2。”和所有子部分名称都是可点击的,并指向正确的位置“A。”不起作用。我该如何解决这个问题无任何其他包装?
编辑
我以为我的例子很简单,但当我把它插到我的盒子里后,它就不能正常工作了:我发布了一个 MWE
\documentclass{article}
\usepackage{titletoc}
\usepackage[
colorlinks=true,
urlcolor=blue,
anchorcolor=blue,
citecolor=blue,
filecolor=blue,
linkcolor=blue,
menucolor=blue,
linktocpage=true,
bookmarks=true,
unicode=true,
pdfa=true,
]{hyperref}
\def\maposectionname{section}
\makeatletter
\g@addto@macro{\appendix}{%
\titlecontents{section}%
[2mm]
{}
{Appendix~%
\hyperlink{%
section.\thecontentslabel
}{%
\thecontentslabel.~%
}%
}%
{\hspace*{0mm}}%
{\hfill\contentspage}
{}
\addtocontents{toc}{\def\protect\maposectionname{appendix}}%
}
\makeatother
\titlecontents{section}%
[9mm]
{}
{\contentslabel[%
\hyperlink{%
\maposectionname.\thecontentslabel
}{%
\thecontentslabel.%
}]%
{7mm}}
{\hspace*{-7mm}}
{\hfill\contentspage}
{}
\titlecontents{subsection}%
[20mm]
{}
{\contentslabel[
\hyperlink{%
subsection.\thecontentslabel%
}{%
\thecontentslabel%
}]%
{12mm}}%
{\hspace*{-12mm}}
{\hfill\contentspage}
{}
\begin{document}
\tableofcontents
%\clearpage
\section{First}
\subsection{FF}
\subsection{FS}
%\clearpage
\section{Second}
\subsection{SF}
\subsection{FF}
%\clearpage
\appendix
\section{App1}
\subsection{App1F}
\subsection{App1S}
\end{document}
答案1
尽管原因令人费解,但这似乎是有效的。;-)
\documentclass{article}
\usepackage{titletoc}
\usepackage[
colorlinks=true,
urlcolor=blue,
anchorcolor=blue,
citecolor=blue,
filecolor=blue,
linkcolor=blue,
menucolor=blue,
linktocpage=true,
bookmarks=true,
unicode=true,
pdfa=true,
]{hyperref}
\def\maposectionname{section}
\makeatletter
\g@addto@macro{\appendix}{%
\addtocontents{toc}{\def\protect\maposectionname{appendix}}%
}
\makeatother
\titlecontents{section}%
[9mm]
{}
{\contentslabel[%
\hyperlink{%
\maposectionname.\thecontentslabel
}{%
\thecontentslabel.%
}]%
{7mm}}
{\hspace*{-7mm}}
{\hfill\contentspage}
{}
\titlecontents{subsection}%
[20mm]
{}
{\contentslabel[
\hyperlink{%
subsection.\thecontentslabel%
}{%
\thecontentslabel%
}]%
{12mm}}%
{\hspace*{-12mm}}
{\hfill\contentspage}
{}
\begin{document}
\tableofcontents
%\clearpage
\section{First}
\subsection{FF}
\subsection{FS}
%\clearpage
\section{Second}
\subsection{SF}
\subsection{FF}
%\clearpage
\appendix
\section{App1}
\subsection{App1F}
\subsection{App1S}
\end{document}
有或没有\clearpage
链接都应该可以。
基于第二个示例的替代方案。
\documentclass{article}
\usepackage{titletoc}
\usepackage[
colorlinks=true,
urlcolor=blue,
anchorcolor=blue,
citecolor=blue,
filecolor=blue,
linkcolor=blue,
menucolor=blue,
linktocpage=true,
bookmarks=true,
unicode=true,
pdfa=true,
]{hyperref}
\makeatletter
\g@addto@macro{\appendix}{%
\titlecontents{section}%
[2mm]
{}
{Appendix~%
\hyperlink{%
appendix.\thecontentslabel
}{%
\thecontentslabel.~%
}%
}%
{\hspace*{0mm}}%
{\hfill\contentspage}
{}
}
\makeatother
\titlecontents{section}%
[9mm]
{}
{\contentslabel[%
\hyperlink{%
section.\thecontentslabel
}{%
\thecontentslabel.%
}]%
{7mm}}
{\hspace*{-7mm}}
{\hfill\contentspage}
{}
\titlecontents{subsection}%
[20mm]
{}
{\contentslabel[
\hyperlink{%
subsection.\thecontentslabel%
}{%
\thecontentslabel%
}]%
{12mm}}%
{\hspace*{-12mm}}
{\hfill\contentspage}
{}
\begin{document}
\tableofcontents
\clearpage
\section{First}
\subsection{FF}
\subsection{FS}
\clearpage
\section{Second}
\subsection{SF}
\subsection{FF}
\clearpage
\appendix
\section{App1}
\subsection{App1F}
\subsection{App1S}
\end{document}