我想制作一个\begin{minted}
区块,在“列表”部分的“目录”上显示,并附上其标签的链接。所以我做了(附上我的 Github 工作仓库的链接)
\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}
标记我的代码以获取正确的链接,以及
\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}%
}
在目录中显示列表列表(没有显示简单的\listoflistings
,所以我放了addcontentsline
),上面有自定义文本。这会产生一个问题,在“源代码列表”中,单击列表的条目会将文档带到封面。我不能做得比这更好:如果我更改了某些内容,或者“源代码列表”条目会转到“图表列表”,或者它消失了。
编辑:复制,尽管我还没能解决我的问题。
答案1
与我的想法相反,问题出在 hyperref 包上。另一个帖子在这里暗示,包含的顺序是假的,但我还必须添加一个\phantomsection
。
因此,我的开场白是
\usepackage[brazil]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
% color
\usepackage[table,dvipsnames]{xcolor}
% Blue links
\usepackage[unicode,colorlinks=true,linkcolor=blue]{hyperref}
% "Natbib" style for references
\usepackage[backend=biber,bibencoding=utf8,style=numeric-comp]{biblatex}
% \makeglossaries
% http://en.wikibooks.org/wiki/LaTeX/Glossary#Using_defined_terms
\usepackage[xindy,toc]{glossaries}
% http://texblog.org/tag/addcontentsline/
\usepackage[numbib]{tocbibind}
% \newminted{cpp}
% [chapter] to number by chapter
\usepackage[chapter]{minted}
% TODO anotations
\usepackage[colorinlistoftodos,portuguese]{todonotes}
\usepackage{float}
\usepackage{caption} % \begin{caption}
\usepackage{csquotes} % required by {babel}
\usepackage{graphicx} % \includegraphics
\usepackage{subcaption} % \begin{subfigure}
\usepackage{verbatim} % \begin{comment}
\usepackage{fullpage} % thinner margins
\usepackage{indentfirst} % indent 1st paragraphs
\usepackage{setspace} % \setstretch
\usepackage{afterpage} % \afterpage https://tex.stackexchange.com/q/88657
% turning 'fi' ligatures off
% http://www.latex-community.org/forum/viewtopic.php?f=5&t=953#p13896
\usepackage{microtype}
\DisableLigatures{encoding = *, family = *}
改变包含的顺序,变成
\usepackage[brazil]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
% color
\usepackage[table,dvipsnames]{xcolor}
\usepackage{caption} % \begin{caption}
\usepackage{csquotes} % required by {babel}
\usepackage{graphicx} % \includegraphics
\usepackage{subcaption} % \begin{subfigure}
\usepackage{verbatim} % \begin{comment}
\usepackage{fullpage} % thinner margins
\usepackage{indentfirst} % indent 1st paragraphs
\usepackage{setspace} % \setstretch
\usepackage{afterpage} % \afterpage https://tex.stackexchange.com/q/88657
% \newminted{cpp}
% [chapter] to number by chapter
\usepackage[chapter]{minted}
% Blue links
\usepackage[unicode,colorlinks=true,linkcolor=blue]{hyperref}
% turning 'fi' ligatures off
% http://www.latex-community.org/forum/viewtopic.php?f=5&t=953#p13896
\usepackage{microtype}
\DisableLigatures{encoding = *, family = *}
% "Natbib" style for references
\usepackage[backend=biber,bibencoding=utf8,style=numeric-comp]{biblatex}
% \makeglossaries
% http://en.wikibooks.org/wiki/LaTeX/Glossary#Using_defined_terms
\usepackage[xindy,toc]{glossaries}
% http://texblog.org/tag/addcontentsline/
\usepackage[numbib]{tocbibind}
% TODO anotations
\usepackage[colorinlistoftodos,portuguese]{todonotes}
\listoflistings
并使用更新命令\phantomsection
% https://tex.stackexchange.com/a/99656/5125
\renewcommand{\listoflistings}{%
\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{\listoflistingscaption}%
\listof{listing}{\listoflistingscaption}%
}
现在,单击目录中的列表条目将引导至列表的正确页面。