目录条目因 \addcontentsline 而放错位置

目录条目因 \addcontentsline 而放错位置

我的博士论文有些问题,特别是目录。
我的前言由许多不同的环境(由自定义类定义)组成,其中包含摘要、致谢、原创性声明等,页码为罗马数字。
此环境的每个部分都有自己的定义和格式,使用命令 \addcontentsline{toc}{chapter} 将其列在目录中。

并且这工作正常。

现在我想将所有这些目录条目分组到一个名为“前言”的虚构部分,将论文的主要章节归入“主要章节”下,并添加附录和一些最终内容,因此我在最开始添加了 \addcontentsline{toc}{part}{Preface},并在论文的所有实际内容之前添加了 \addcontentsline{toc}{part}{Main chapters}。
不幸的是,结果有点奇怪,如您在附图中看到的那样,特别是 hyperref 部分正常工作,而目录却不能正常工作。
我使用的代码片段如下:

\phantomsection
\addcontentsline{toc}{chapter}{Contents}
\tableofcontents            % generate and include a table of contents
% end roman page numbering
\end{romanpages}
\phantomsection
\addcontentsline{toc}{part}{Main chapters}
\phantomsection
\cleardoublepage
%now include the files of latex for each of the chapters etcbut I prefered to insert it there
\include{\introductionchapter/Introduction}
\cleardoublepage

romanpages 环境定义为:

\newenvironment{romanpages}
    {
    \cleardoublepage
    \setcounter{page}{1}
    \renewcommand{\thepage}{\roman{page}}
    }
    {
    \cleardoublepage
    \setcounter{page}{1}
    \renewcommand{\thepage}{\arabic{page}}
}

如您所见,我尝试使用 \phantomsection 进行了一些尝试,但没有任何结果。
有什么办法可以解决这个问题吗?

谢谢,
Jacopo

PS 所包含的代码不是 MWE,我没有提供它,因为我无法用一个简单的例子重现这个问题

在此处输入图片描述

相关内容