![使用 /setcounter 後,詞彙表中的 Hyperref 會導致錯誤的頁面](https://rvso.com/image/420748/%E4%BD%BF%E7%94%A8%20%2Fsetcounter%20%E5%BE%8C%EF%BC%8C%E8%A9%9E%E5%BD%99%E8%A1%A8%E4%B8%AD%E7%9A%84%20Hyperref%20%E6%9C%83%E5%B0%8E%E8%87%B4%E9%8C%AF%E8%AA%A4%E7%9A%84%E9%A0%81%E9%9D%A2.png)
我有一個包含程式碼的文檔,我在下面添加了它。文件的前兩頁是標題頁和目錄頁。這兩頁不應計算在內,因為內容本身是從第三頁開始的。因此,第三頁的數字應該是 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
。