使用 /setcounter 后,词汇表中的 Hyperref 会导致转到错误页面

使用 /setcounter 后,词汇表中的 Hyperref 会导致转到错误页面

我有一个文档,其中包含我在下面添加的代码。文档的前两页是标题页和目录页。这两页不应计算在内,因为内容本身从第三页开始。因此,第三页应该有数字 1。为此,我在“内容”页面样式中添加了 \setcounter{page}{1}。执行此操作后,词汇表中的页码也更改为 1,这是应该的。当我单击 1 到达词汇表中描述的单词所在的页面时,hyperref 会将我引导到标题页,即文档的第一页。这是错误的,因为它应该将我引导到文档的第三页,该页码编号为 1。有什么方法可以解决这个问题吗?

这是我的文档的代码:

\documentclass{article}

\usepackage[headsepline,footsepline]{scrlayer-scrpage}
\usepackage{graphicx,xcolor}
\usepackage[margin=38mm,includeheadfoot]{geometry}
\usepackage{setspace, fontspec, hyperref}
\usepackage[acronym]{glossaries}    
\pagenumbering{arabic}

\DeclareNewLayer[
    background,
    topmargin,
    mode=picture,
    contents={\includegraphics[height=\layerheight,width=\layerwidth]{Picture1.png}}
]{top}

\DeclareNewLayer[
    background,
    bottommargin,
    mode=picture,
    contents={\includegraphics[height=\layerheight,width=\layerwidth]{Picture2.png}}
]{bottom}

\defpairofpagestyles{Titlepage}{}

\AddLayersToPageStyle{Titlepage}{top,bottom}

\newpairofpagestyles[scrheadings]{Tableofcontents}
{
    \clearscrheadfoot
    \ihead{Author}
    \chead{Title}
    \ohead{\includegraphics{Logo.png}}
}

\newpairofpagestyles[scrheadings]{Content}
{
    \clearscrheadfoot
    \setcounter{page}{1}
    \ihead{Author}
    \chead{Title}
    \ohead{\includegraphics{Logo.png}}
    \cfoot{Page \pagemark}
}

\makeglossaries
\newglossaryentry{Test}
{
    name=Test,
    description={Test}
}

\begin{document}
    \begin{titlepage}
      \KOMAoption{headsepline}{false}
      \KOMAoption{footsepline}{false}
      \begin{center}
        \thispagestyle{Titlepage}        
        Titlepage
      \end{center}
    \end{titlepage}

    \thispagestyle{Tableofcontents}
    \tableofcontents
    \clearpage
    
    \thispagestyle{Content}
    This is a \gls{Test}

    \printglossary
 \end{document}

答案1

对第一页(隐藏页码的页面)使用不同的编号系统。

\documentclass{article}
\usepackage[headsepline,footsepline]{scrlayer-scrpage}
\usepackage{graphicx}
%\usepackage{xcolor}% not used in the example
\usepackage[margin=38mm,includeheadfoot]{geometry}
%\usepackage{setspace}% not used in the example
\usepackage{fontspec}
\usepackage{hyperref}
\usepackage[acronym]{glossaries}

\DeclareNewLayer[
    background,
    topmargin,
    mode=picture,
    contents={\putLL{\includegraphics[height=\layerheight,width=\layerwidth]{example-image-a}}}
]{top}

\DeclareNewLayer[
  background,
  bottommargin,
  mode=picture,
  contents={\putLL{\includegraphics[height=\layerheight,width=\layerwidth]{example-image-b}}}
]{bottom}

\DeclarePageStyleByLayers{Titlepage}{top,bottom}

\newpairofpagestyles[scrheadings]{Tableofcontents}
{
  \clearpairofpagestyles% <- replace outdated command
  \ihead{Author}
  \chead{Title}
  \ohead{\smash{\includegraphics[height=1cm]{example-image}}}% use \smash to hide the height of the image
}

\newpairofpagestyles[scrheadings]{Content}
{
  \clearpairofpagestyles% <- replace outdated command
  \ihead{Author}
  \chead{Title}
  \ohead{\smash{\includegraphics[height=1cm]{example-image}}}% use \smash to hide the height of the image
  \cfoot{\pagemark}
}
\renewcommand*{\pagemark}{{\usekomafont{pagenumber}Page~\thepage}}

\newcommand*{\Content}{%
  \cleardoublepage
  \pagenumbering{arabic}% resets the page number to 1
  \pagestyle{Content}%
}

\makeglossaries
\newglossaryentry{Test}
{
  name=Test,
  description={Test}
}

\begin{document}
\pagenumbering{roman}
\begin{titlepage}
  \thispagestyle{Titlepage}
  \begin{center}
    Titlepage
  \end{center}
\end{titlepage}

\pagestyle{Tableofcontents}
\tableofcontents

\Content
This is a \gls{Test}
\printglossary
\end{document}

补充说明:不要在页面样式的设置中更改页面计数器的值Content

相关内容