I wanted to make a \begin{minted}
block to show on the ToC in Listings section with a link to its label. So I did (with links to my Github working repo)
\begin{listing}[!h]
\begin{minted}[
linenos,
frame=single,
numbersep=6pt,
baselinestretch=1,
fontfamily=courier,
gobble=4,
fontsize=\tiny,
]{text}
code code code
\end{minted}
\caption{some caption}
\label{code:mytextfile}
\end{listing}
to label my code to get the right link, and
\renewcommand\listingscaption{Code}
\renewcommand\listoflistingscaption{List of Source codes}
% https://tex.stackexchange.com/a/99656/5125
\renewcommand{\listoflistings}{%
\cleardoublepage
\addcontentsline{toc}{chapter}{\listoflistingscaption}%
\listof{listing}{\listoflistingscaption}%
}
to show a List of Listings on the ToC (were not showing with a simple \listoflistings
, so I put addcontentsline
), with custom texts on it. This produces a problem that, at the "Source code List", clicking on the entry for the listing takes the document to the cover. I cannot go better than this: if I change something, or the "List of Source codes" entry takes to "List of Figures", or it disappears.
Edit: duplicate, althought I could not fix my problem yet.
Best Answer
Going against what I thought it was, the problem was the hyperref package. As this other post here hinted, the include's order was bogus, but also I had to add a
\phantomsection
.So, my preamble was
Changing the include's order, turned into
and the renew command for
\listoflistings
with the\phantomsection
Now, clicking the list of listings entry on table of contents guides to the right page of the listing.