带有铸币和标题的多页列表

带有铸币和标题的多页列表

我有源长列表(2+ 页),我使用 minited 通过 \inputminted 突出显示。我希望在 \listoflistings 和我的文本中引用我的代码时,列表有标题和参考标签。

我尝试了所附的代码但收到警告。

包标题警告:对于输入行 11 上的这个(标题)特定 \caption,选项“hypcap=true”将被忽略。请参阅标题包文档以获取解释。

有人能解释一下正确的做法吗?我在 13 个地方都这样做过,所以我想了解这是实现这一目标的最佳方法吗?

谢谢

斯图尔特

\documentclass[a4paper,11pt]{report}
\usepackage[hidelinks]{hyperref}  % I use XeLaTeX to pdf with hyperlinks
\usepackage{minted}
\usepackage{subcaption}  %Include this in MVE as I have figures with subcaption elsewhere

\begin{document}
\listoflistings
\newpage
In my Listing~\ref{label-to-long-listing} I have more than 2 page source code listing.
\inputminted[linenos, breaklines=true,fontsize=\scriptsize, numberblanklines=false]{bash}{long.txt}
\captionof{listing}{Long Listing ToC\label{label-to-long-listing}}

\end{document}

答案1

minted提供listing将代码块置于浮动环境中的环境。在里面listing你可以提供一个\caption和一个\label

\documentclass[a4paper,11pt]{report}
\usepackage[hidelinks]{hyperref}  % I use XeLaTeX to pdf with hyperlinks
\usepackage{minted}
\usepackage{subcaption}  %Include this in MVE as I have figures with subcaption elsewhere

\usepackage{filecontents}
\begin{filecontents*}{long.txt}
  #!/bin/sh
  /opt/vc/bin/tvservice -o
\end{filecontents*}

\begin{document}
\listoflistings
\cleardoublepage
In my Listing~\ref{label-to-long-listing} I have more than 2 page source code listing.
\begin{listing}[H]
\inputminted[linenos, breaklines=true,fontsize=\scriptsize, numberblanklines=false]{bash}{long.txt}
\caption{Long Listing ToC\label{label-to-long-listing}}
\end{listing}

\end{document}

在此处输入图片描述

另一种方法是(因为你想要分页符)使用

\usepackage[all]{hypcap}

\captionof也可根据需要在组内使用。

\documentclass[a4paper,11pt]{report}
\usepackage[hidelinks]{hyperref}  % I use XeLaTeX to pdf with hyperlinks
\usepackage[all]{hypcap}    %% use after hyperref
\usepackage{minted}
\usepackage{subcaption}  %Include this in MVE as I have figures with subcaption elsewhere

\usepackage{filecontents}
\begin{filecontents*}{long.txt}
  #!/bin/sh
  /opt/vc/bin/tvservice -o
\end{filecontents*}

\begin{document}
\listoflistings
\cleardoublepage
In my Listing~\ref{label-to-long-listing} I have more than 2 page source code listing.
\bgroup                    %%<<-- use this
\inputminted[linenos, breaklines=true,fontsize=\scriptsize, numberblanklines=false]{bash}{long.txt}
\captionof{listing}{Long Listing ToC\label{label-to-long-listing}}
\egroup                  %% and this

\end{document}

相关内容