hyperref 始终指向文档的第一页

hyperref 始终指向文档的第一页

我正在用 LaTeX 打字写我的论文。我用过hyperref。参考书目中有两篇论文。论文 1 引用在第一页,论文 2 引用在第二页。

当我点击参考书目中论文编号 1 下方的红色数字时,它错误地指向了文档的标题页。但论文编号 2 没有问题。请帮助我。我希望论文编号 1 指向正确的页面。

另外,在我的文档中,我不想要“第 0 章,概要”。我只想要“概要”,即不提及第 0 章标记。我只希望这一章有这个标记,而不是后面的章节。我还希望概要出现在文档的内容中。请帮我解决这个问题。

我在下面附上了我的.tex代码。

\documentclass[12pt, reqno, a4paper]{book}

\usepackage{fancyhdr}%, setspace}

\usepackage[pagebackref]{hyperref}
\hypersetup{
     colorlinks = true, linkcolor = red,
     citecolor   = blue,
     urlcolor    = blue,
}


\begin{document}

\begin{titlepage}
\begin{center}
{\bf Title page}
\end{center} 
\end{titlepage}




\pagestyle{plain}
\pagenumbering{roman}
\addtocounter{page}{1} 

%\thispagestyle{empty}

$\textnormal{ }$
\vspace{9cm} 
\begin{center}
{\bf \Large{To my Parents}}
\end{center}


{\Large
\tableofcontents}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\chaptername\ \thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\renewcommand{\headrulewidth}{0.1pt}
\renewcommand{\footrulewidth}{0.1pt}
\fancyhf{}
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark} 
\fancyhead[RE]{\bfseries\leftmark}
\lfoot{Anjan Gupta, TIFR, Mumbai.}




\pagenumbering{arabic}
\setcounter{chapter}{-1}  % to start Chapter numbers from 0

\chapter{synopsis}
\setcounter{page}{1}
In \cite[Theorem 4.1]{cr} it is shown that this is indeed true in the absolute case.

\newpage

we shall now use the result \cite{sfmaa}

\begin{thebibliography}{VAST}

\bibitem{cr} Paper 1.

\bibitem{sfmaa} Paper 2.

\end{thebibliography}

\end{document}

答案1

chapter问题已在评论中得到解决,因此我尝试解决重复的页面锚点问题。

还有另一种解决方案,应该是最后手段,由 Werner 提出,但他删除了他的答案,所以不是每个人都能看到那篇帖子,所以我只是为了方便而重复一遍,简而言之:

hypertexnames=false

现在,经常受到批评,所以我深入研究了和hypertexnames的精彩代码。backrefhyperref

关于等的投诉的原因name(page.1)是,每次调用宏时\pagenumbering都会重置数字,导致多个页面包含该数字,从而混淆超链接。使用statementss,这可以解决问题。如果不这样做,则必须使用更棘手的设置。page\pagenumbering1\clearpage

我通过修补命令、在和之间\Hy@EveryPageAnchor注入宏(有效地)解决了这个问题。\pagenumberingchangespage.\thepage

\pagenumberingchanges使用\thepagenumberingcalls,它是的计数器格式化程序,每次使用pagenumberingcalls时都会分步进行。\pagenumbering

此外,每次应用命令时都\pagenumberingchanges必须将此宏写入.brf生成的文件中。backref\cite

这会消除相同page.XYZ锚点的多次出现,但是,如果有人直接或通过 操纵页面计数器,它就不是万无一失的\setcounter{page}{}

链接现在正常并且指向正确的位置。

使用检查页码值是否已更改的版本进行更新

\documentclass[12pt, a4paper]{book}

\usepackage{fancyhdr}%, setspace}

\usepackage[headheight=16pt]{geometry}% Fix the complaint of fancyhdr

\usepackage{xpatch}

\usepackage[pagebackref]{hyperref}
\hypersetup{
  colorlinks = true, linkcolor = red,
  citecolor   = blue,
  urlcolor    = blue,
}

\newcounter{pagenumberingcalls}
\newcommand{\pagenumberingchanges}{\thepagenumberingcalls}


\makeatletter

\AtBeginDocument{%

  % Each time the \pagenumbering command is called, increase a counter
  \xpretocmd{\pagenumbering}{\edef\@previouspagenumberingcalls{\thepagenumberingcalls}\stepcounter{pagenumberingcalls}}{}{}
  % Each time \cite is used, write the state of the counter to the .brf file
  \xpretocmd{\cite}{\write@to@brffile}{}{}

%Write the current pagenumbering change state to the .brf file
  % Idea from backref.sty (by David Carlisle and Sebastian Rahtz)
  \newcommand{\write@to@brffile}{%
    \edef\temp@@a{\@previouspagenumberingcalls}%
    \edef\temp@@b{\pagenumberingchanges}%
    \ifx\temp@@a\temp@@b
    \else
    \edef\@previouspagenumberingcalls{\thepagenumberingcalls}%
    \protected@write\@auxout{}{%
      \string\@writefile{brf}{%
        \string\renewcommand{\protect\pagenumberingchanges}{\thepagenumberingcalls}%
      }%
    }%  
    \fi
  }

\@ifpackageloaded{hyperref}{%
  \long\def\hyper@page@backref#1#2#3{\hyperlink{page.\pagenumberingchanges.#1}{#1}}
  \let\backrefxxx\hyper@page@backref

  \xpatchcmd{\Hy@EveryPageAnchor}{%
    \hyper@@anchor{page.\@the@H@page}%
  }{%
    \hyper@@anchor{page.\pagenumberingchanges.\@the@H@page}%
  }{\typeout{Patch 1 succeeded}}{\typeout{Patch failure for EveryPageAnchor}}
  \xpatchcmd{\Hy@EveryPageAnchor}{%
    \hyper@@anchor{page.\the\c@page}%
  }{%
    \hyper@@anchor{page.\pagenumberingchanges.\the\c@page}%
  }{\typeout{Patch 2 succeeded}}{}
  \xpatchcmd{\Hy@EveryPageAnchor}{%
    \hyper@@anchor{page.\the\Hy@pagecounter}%
  }{%
    \hyper@@anchor{page.\pagenumberingchanges.\the\Hy@pagecounter}%
  }{\typeout{Patch 3 succeeded}}{}
  }{%Nope, no hyperref loaded --> just be silent%
  }
}
\makeatother


\begin{document}
\begin{titlepage}
  \begin{center}
    \bfseries Title page
  \end{center} 
\end{titlepage}


\pagestyle{plain}
\pagenumbering{roman}
\addtocounter{page}{1}%????

{\Large
\tableofcontents}


\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\chaptername\ \thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\renewcommand{\headrulewidth}{0.1pt}
\renewcommand{\footrulewidth}{0.1pt}
\fancyhf{}
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark} 
\fancyhead[RE]{\bfseries\leftmark}
\lfoot{Anjan Gupta, TIFR, Mumbai.}



\pagenumbering{arabic}
\setcounter{chapter}{-1}  % to start Chapter numbers from 0

\chapter{synopsis}
In \cite[Theorem 4.1]{cr} it is shown that this is indeed true in the absolute case.

\clearpage

we shall now use the result \cite{sfmaa}

\begin{thebibliography}{VAST}
\bibitem{cr} Paper 1.

\bibitem{sfmaa} Paper 2.

\end{thebibliography}
                                %
\end{document}

您可以在此处找到相关但不同的问题:https://tex.stackexchange.com/a/373678/31729

答案2

您可以使用\frontmatter\mainmatter(也许\backmatter)来更改页码(无需操作页码和章节计数器)。

\documentclass[12pt, reqno, a4paper]{book}

\usepackage{fancyhdr}%, setspace}

\usepackage[pagebackref]{hyperref}
\hypersetup{
     colorlinks = true, linkcolor = red,
     citecolor   = blue,
     urlcolor    = blue,
}

\begin{document}
\frontmatter

\begin{titlepage}
  \begin{center}
    {\bf Title page}
  \end{center} 
\end{titlepage}

\pagestyle{plain}

%\thispagestyle{empty}

$\textnormal{ }$
\vspace{9cm} 
\begin{center}
{\bf \Large{To my Parents}}
\end{center}


{\Large
\tableofcontents}

\mainmatter

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\chaptername\ \thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\renewcommand{\headrulewidth}{0.1pt}
\renewcommand{\footrulewidth}{0.1pt}
\fancyhf{}
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark} 
\fancyhead[RE]{\bfseries\leftmark}
\lfoot{Anjan Gupta, TIFR, Mumbai.}



\chapter*{synopsis}
\addcontentsline{toc}{chapter}{Synopsis}
In \cite[Theorem 4.1]{cr} it is shown that this is indeed true in the absolute case.

\newpage

we shall now use the result \cite{sfmaa}

\begin{thebibliography}{VAST}

\bibitem{cr} Paper 1.

\bibitem{sfmaa} Paper 2.

\end{thebibliography}

\end{document}

相关内容