操纵目录样式来模拟示例。Hyperref 问题

操纵目录样式来模拟示例。Hyperref 问题

编辑:

我解决了大部分原始问题,因此我正在重写这个问题,它本质上仍然是相同的,但现在我可以发布更好的 MWE。

我遇到的问题是将目录中的点变成链接到相关章节的链接。本质上,我希望可点击的链接从章节文本一直延伸到页码,以便它包含中间的点。我尝试了许多可能的解决方案,但似乎无法让它发挥作用。

最终我的目标是模仿给出的示例页面这里,我认为我已经设法做到了,除了一些我仍在完成的小格式(例如删除小节中的数字和更正一些缩进)。我似乎无法弄清楚的唯一部分是使点与文本和页码一起可点击。

这是独立的 MWE:(请记住它有点长,因为问题的一部分是包交互,所以我需要将它们全部包含在它们的设置中,以确保任何潜在的解决方案都能避免包冲突)。

\documentclass{report}
\makeatletter
\usepackage{etoolbox}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage[titles]{tocloft}
\usepackage[linktoc=all]{hyperref}% Use this to provide intra-pdf hyperlinking and better toc
                                  % linktoc=all used to extend the hyperlink across the dotted lines.... in theory.
\hypersetup{%               % Setup the coloring of the links. 
%                           % Currently the only necessary one is "colorlinks=true" and "linkcolor=blue".
    colorlinks   = true,    % Colours links instead of ugly boxes
    urlcolor     = blue,    % Colour for external hyperlinks
    linkcolor    = blue,    % Colour of internal links
    citecolor    = blue     % Colour of citations, could be ``red''
    }

\usepackage{titlesec}% Use this to manipulate default chapter styling
\usepackage[margin=1in]{geometry}
\raggedright
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand\headrulewidth{0pt}
\lhead{}\chead{}\rhead{}
\cfoot{\vspace*{1.5\baselineskip}\thepage}


\usepackage[nodisplayskipstretch]{setspace}%
\doublespacing% Make everything double spaced by default.
\preto\longtable{\par\singlespacing}% Pre-append using longtables to make sure that tables are single spaced.
\preto\itemize{\par\singlespacing}% Pre-append singlespace to itemize to account for single space bullet point lists.


\titleformat{\chapter}[hang]{\large}{}{0pt}{\centering\singlespacing\MakeUppercase}{\raggedright\doublespacing}
\titleformat{\part}[hang]{\large}{}{0pt}{\centering\singlespacing\MakeUppercase}{\raggedright\doublespacing}
\renewcommand{\contentsname}{TABLE OF CONTENTS}%

\renewcommand{\cftdotsep}{1}

\renewcommand\cftchapfont{\normalfont}%         Remove Bold font from TOC
\renewcommand\cftchappagefont{\normalfont}%     Remove Bold font from TOC
\renewcommand\cftpartfont{\normalfont}%         Remove Bold font from TOC
\renewcommand\cftpartpagefont{\normalfont}%     Remove Bold font from TOC
\setlength{\cftbeforechapskip}{1pt}%
\setlength{\cftbeforepartskip}{1pt}%
\setlength{\cftbeforesecskip}{-6pt}%
\setlength{\cftbeforesubsecskip}{-6pt}%
\setlength{\cftbeforesubsubsecskip}{-6pt}%
\def\cftchapleader{\hyperlink{\mylabel}{\cftdotfill{\cftsecdotsep}}}% Add in the dotted lines between the name and page number in TOC

\begin{document}
\setcounter{secnumdepth}{-1}% We don't want chapter numbers until later, 
                            % So let's kill off the table of contents depth detector until we want to start counting.

\chapter{DEDICATION}
Some dedication stuff goes here.

\chapter{ACKNOWLEDGEMENTS}
\label{Acknowledgements}
\hypertarget{acknowledgements}{}
\edef\mylabel{acknowledgements}

Some Acknowledgements Text here.

\tableofcontents

\listoftables
\addcontentsline{toc}{chapter}{LIST OF TABLES}
\hypertarget{LOT}{}
\edef\mylabel{LOT}
%\addtocontents{toc}{\protect\contentsline{chapter}{LIST OF TABLES}{}{\@currentHref}}

\listoffigures
\addcontentsline{toc}{chapter}{LIST OF FIGURES}
\hypertarget{LOF}{}
\edef\mylabel{LOF}
%\addtocontents{toc}{\protect\contentsline{chapter}{LIST OF FIGURES}{}{\@currentHref}}


%\def\cftchapleader{\hyperlink{abbreviations}{\cftdotfill{\cftsecdotsep}}}%
\hypertarget{abbreviations}{}
\chapter{ABBREVIATIONS}
\label{abbreviations}
\edef\mylabel{abbreviations}

Some Abbreviation text would go here.


\chapter{ABSTRACT}
\label{abstract}

Some Abstract text goes here.


\addtocontents{toc}{\protect\contentsline{part}{CHAPTER}{}{}}
\setcounter{secnumdepth}{3}% Now we want toc numbering.

\chapter{First real chapter}
Some intro or something else here

\section{A `section', toc should be indented some.}

Some section info.

\subsection{A `subsection', toc should be indented even more.}

\chapter{Second real chapter}
More text here.

\setcounter{secnumdepth}{-1}% We don't want the Appendix to have a number, but it should be linked.
\chapter*{APPENDIX}
\label{appendix}

\addtocontents{toc}{\protect\contentsline{part}{APPENDIX}{}{\@currentHref}}
\setcounter{secnumdepth}{3}% Now we number again.


\chapter{REFERENCES}
\label{references}

\chapter{BIOGRAPHY}
\label{biography}

\end{document}

需要明确的是,我感兴趣的具体行是,\def\cftchapleader{\hyperlink{\mylabel}{\cftdotfill{\cftsecdotsep}}}%这是我最后一次尝试使用\hyperlinkhyperref 包中的点链接到正确的位置。但即使尝试更新\mylabel每个部分似乎也无法正确形成链接, 也是如此\@currentHref。我怀疑这是一个扩展问题,因为实际的 ToC 形成时间与标签和事物形成时间有关。

答案1

使用它将章节点链接到正确的页面:

\makeatletter
\def\cftchapleader{\hyper@linkstart{link}{\Hy@tocdestname}{\cftdotfill{\cftsecdotsep}}\hyper@linkend}
\makeatletter

您可以删除所有超目标和 \mylabel 定义等。

相关内容