# Toc entry misplaced with \addcontentsline

My preface consists in many different environments (defined by a custom class) containing the abstract, the acknowledgements, the statement of originality, etc and with pages numbered with roman numbers.
Everyone of this environment has its own definition and format with the command \addcontentsline{toc}{chapter} to list it in the ToC.

And this work properly.

Now I would like to group all these ToC entries into a fictional part called "Preface", the main chapters of my thesis under "Main chapters" and so on with the appendixes and some final stuff, so I added \addcontentsline{toc}{part}{Preface} at the very beginning and \addcontentsline{toc}{part}{Main chapters} before all the actual content of my thesis.
Unfortunatly, the result is a bit strange, as you can see in the attached picture, in particular the hyperref part work properly while the ToC doesn't.
A snippet of the code I'm using is:

\phantomsection
% end roman page numbering
\end{romanpages}
\phantomsection
\phantomsection
\cleardoublepage
%now include the files of latex for each of the chapters etcbut I prefered to insert it there
\include{\introductionchapter/Introduction}
\cleardoublepage

with the romanpages environment defined as:

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

As you can see, I tried to play around a bit with \phantomsection, but without any results.
Any idea on how to fix this?

Thanks,
Jacopo

P.S. the code included is not an MWE and I'm not supplying it because I cannot really reproduce the problem with a simple example

• Don't use \include, use \input instead. – Ulrike Fischer Apr 17 at 17:02
• unrelated but you can simplify setcounter{page}{1} \renewcommand{\thepage}{\roman{page}} to \pagenumbering{roman} – David Carlisle Apr 17 at 17:58
• @UlrikeFisher can you add more details about this choice? Reading around, to me, include seems better because it will not compile not modify stuff.... (and by the way, I'm also using that command in the preamble or in child files) – Jacopo Remondina Apr 18 at 21:17
• @DavidCarliste thanks for the tip, but that definition is in my class file, so I prefer to not change it – Jacopo Remondina Apr 18 at 21:18