我最近发现,我无法从与目录中章节/节号相关的超链接移动到章节/节所在的页面 - 它看起来像被阻塞了...实际上,我可以从正文中存在的编号移动。我该怎么做才能让它在这里和这里工作?
代码:
\documentclass[12pt, a4paper]{book}
\usepackage[left=2.5cm, right=2.5cm, bottom=2.5cm, headheight=15pt]{geometry} %marginesy
%\usepackage[utf8]{inputenc} %kodowanie polskich znaków
\usepackage[polish]{babel}
\babelprovide[transforms = oneletter.nobreak]{polish} %brak wiszących liter na końcu zdania
\selectlanguage{polish}
\usepackage{fancyhdr}
\usepackage{tocloft} %nowoczesny spis treści
\usepackage{xpatch}
\renewcommand{\cftpartpresnum}{\hfil}
\renewcommand{\cftpartleader}{\hfil}
\renewcommand{\cftchapaftersnum}{.} %kropki po numerze rozdziału
\renewcommand{\cftsecaftersnum}{.} %kropki po numerze sekcji
\renewcommand{\cftchappresnum}{\bfseries} %numer pogrubiony przy rozdziale
\renewcommand{\cftchapleader}{\normalfont\cftdotfill{\cftchapdotsep}} %kropki przy rozdziałach w spisie treści
\renewcommand\cftchappagefont{\bfseries\normalsize}
\setlength{\cftchapnumwidth}{1cm} %odstęp między kropką a nazwą rozdziału w spisie treści
\renewcommand{\cftchapfont}{\normalfont\large} %duża czcionka rozdziału
\renewcommand{\cftpartfont}{\bfseries\Large}
\usepackage{caption}
\usepackage{subcaption}
%\usepackage{secdot}
\usepackage{fontspec}
\usepackage{graphicx}
\usepackage[nottoc, notlof]{tocbibind}
\usepackage[bookmarksnumbered, pdfpagelayout=TwoPageRight, pagebackref, linktoc=all]{hyperref}
\usepackage{bookmark}
\usepackage{lipsum}
\usepackage[Bjornstrup]{fncychap} %nowoczesny wygląd rozdziału
\makeatletter
\patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}
\makeatother %zabezpieczenie przed tworzeniem nowej strony przed rozdziałem
%\renewcommand{\thesection}{\thechapter.\arabic{section}}
\renewcommand{\thechapter}{\hyperref[toc]{\arabic{chapter}}}
\renewcommand{\thesection}{\hyperref[toc]{\arabic{chapter}.\arabic{section}.}}
\makeatletter
\let\sv@endpart\@endpart
\def\@endpart{\thispagestyle{empty}\sv@endpart}
\makeatother
\usepackage{xparse}
\AtBeginDocument{
\let\oldchapter\chapter
\RenewDocumentCommand{\chapter}{s o m}{%
\IfBooleanTF{#1}
{\oldchapter*{\hyperref[toc]{#3}}}% \chapter*[..]{...}
{\IfValueTF{#2}
{\oldchapter[#2]{\hyperref[toc]{#3}}}% \chapter[..]{...}
{\oldchapter[#3]{\hyperref[toc]{#3}}}% \chapter{...}
%\label{chapter-\thechapter}% \label this chapter
}%
}
\let\oldsection\section
\RenewDocumentCommand{\section}{s o m}{%
\IfBooleanTF{#1}
{\oldsection*{\hyperref[toc]{#3}}}
{\IfValueTF{#2}
{\oldsection[#2]{\hyperref[toc]{#3}}}
{\oldsection[#3]{\hyperref[toc]{#3}}}
%\label{section-\thesection}
}%
}
\let\oldpart\part
\RenewDocumentCommand{\part}{s o m}{%
\IfBooleanTF{#1}
{\oldpart*{\hyperref[toc]{#3}}}
{\IfValueTF{#2}
{\oldpart[#2]{\hyperref[toc]{#3}}}
{\oldpart[#3]{\hyperref[toc]{#3}}}
\label{part-\thepart}
}%
}
}
\hbadness=99999
\hfuzz=100.002pt
\begin{document}
\tableofcontents\label{toc}
\addtocontents{toc}{\protect\thispagestyle{empty}}
\newpage
\thispagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\renewcommand{\headrulewidth}{0pt}
\setcounter{part}{0}
\addtocontents{toc}{\cftpagenumbersoff{part}}
\part*{\texorpdfstring{\vspace*{2cm} Część I \\[-1.5cm] Część pierwsza}{Część pierwsza}}
\addcontentsline{toc}{part}{\texorpdfstring{I. Część pierwsza}{Część pierwsza}}
\setcounter{chapter}{0}
\chapter{Rozdział 1}
\pagenumbering{arabic}
\setcounter{page}{5}
\lipsum[1]
\stepcounter{figure}
\cftaddtitleline{lof}{figure}{\large Ryc. \textbf{\thefigure.} Napis}{\textbf{\thepage}}
\begin{figure}[h!]
\centering
\includegraphics[width=3cm]{example-image-a}
\caption*{Napis}
\end{figure}
\section{Sekcja 1}
\lipsum[2]
\stepcounter{figure}
\cftaddtitleline{lof}{figure}{\large Ryc. \textbf{\thefigure.} Napis 2}{\textbf{\thepage}}
\stepcounter{figure}
\cftaddtitleline{lof}{figure}{\large Ryc. \textbf{\thefigure.} Napis 3}{\textbf{\thepage}}
\newpage
\bookmarksetup{startatroot}
\end{document}
答案1
不要重新定义\thechapter
并\thesection
添加链接。而是通过重新定义 fncychap 中的命令来重新定义章节编号:
\renewcommand{\DOCH}{%
\settowidth{\py}{\CNoV\thechapter}
\addtolength{\py}{-10pt} % Amount of space by which the
% % number is shifted right
\fboxsep=0pt%
\colorbox[gray]{.85}{\rule{0pt}{40pt}\parbox[b]{\textwidth}{\hfill}}%
\kern-\py\raise20pt%
\hbox{\color[gray]{.5}\CNoV\hyperref[toc]{\thechapter}}\\%<<<---
}
并添加指向章节编号的链接重新定义\@seccntformat
:
\makeatletter
\renewcommand\@seccntformat[1]{\csname sec#1numberformat\endcsname{\csname the#1\endcsname}\quad}
\newcommand\secsectionnumberformat[1]{\hyperref[toc]{#1}}
\makeatother
(我认为这些链接没什么用。我不喜欢文档中有太多活动区域,因为这样你就必须小心不要点击或触摸屏幕,因为它会将你移动到不想要的地方。如果我想进入目录,我会使用书签。)