I have to use \addtocontents
at some places to fully customize the data of some of the lines in my toc (that is, include or not include page numbers, include or not include section / chapter numbers and specify them in some cases where included) and I can't use \addcontentsline
since it doesn't allow me to specify chapter or section number. Now, the entries show up in the toc but I can't manage to link them properly, any suggestions?
MWE:
\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{tocloft}
\usepackage{hyperref}
\begin{document}
\tableofcontents
%======== USING REGULAR ENTRIES ========
\chapter{Chapter 1} % properly linked of course
{\LARGE This is chapter 1}
\section{Section 1-1} % well linked as well
{\LARGE This is chapter 1 section 1}
\clearpage
%======== USING \addcontentsline ========
\phantomsection
\addcontentsline{toc}{chapter}{Chapter 2} % works fine
{\LARGE This is chapter 2}
\clearpage
\phantomsection
\addcontentsline{toc}{section}{Section 2-1} % link works
{\LARGE This is chapter 2 section 1}
\clearpage
%======== USING \addtocontents ========
\phantomsection
\addtocontents{toc}{\protect\contentsline{chapter} % this link does not work
{\protect\numberline{3}Chapter 3}{\thepage}{}}
{\LARGE This is chapter 3}
\clearpage
\phantomsection
\addtocontents{toc}{\protect\contentsline{section}{\protect\numberline{3-1}Section 3-1}{\thepage}{section*.2.4}} % ... neither does this
{\LARGE This is chapter 3 section 1}
\clearpage
\end{document}
I understand I have to put the link as the last argument to \contentsline
but I can't get it to work... I have tried with:
chapter*.\thechapter
chapter*.\thepage
section*.\thesection
... etcetera... I can make it work with \page.<PAGENO>
but I don't think that's a very nice solution... Also, I can't have chapters or sections like \section*{}
since I actually don't even want a section header or anything at the desired places...
\addcontentsline
-- but the wholenon-chapter/section
approach is a little bit weird