使用minted
,我排版了长度超过一页的列表。但是,使用listing
附带的环境minted
不起作用,因为它不会在页面末尾中断。我找到了一个可能的解决方案,即使用,captionof
这样它仍然出现在列表列表中。
但是,使用它之后,parskip 会被重置,并且half
对于其下方的任何文本,该选项都不再使用。
\documentclass[
12pt,
paper=a4,
parskip=half ]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{libertine}
\usepackage[libertine,cmintegrals,cmbraces,vvarbb]{newtxmath}
\usepackage{inconsolata}
\usepackage{minted}
\usepackage{caption}
\usepackage{lipsum}
\begin{document}
\lipsum
\begin{minted}{python}
def foo():
# Here would be code longer than one page
return 0
\end{minted}
\captionof{listing}{Some Text}
\lipsum
\end{document}
答案1
您会收到一条警告:
Package caption Warning: \captionsetup{type*=...} or \captionof
(caption) outside box or environment on input line 24.
See the caption package documentation for explanation.
这是您遇到的问题的原因。作为补救措施,请将其放入minted
组中
\bgroup
\begin{minted}{python}
def foo():
# Here would be code longer than one page
return 0
\end{minted}
\captionof{listing}{Some Text}
\egroup
您的代码:
\documentclass[
12pt,
paper=a4,
parskip=half ]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{libertine}
\usepackage[libertine,cmintegrals,cmbraces,vvarbb]{newtxmath}
\usepackage{inconsolata}
\usepackage{minted}
\usepackage{caption}
\usepackage{lipsum}
\begin{document}
\lipsum
\bgroup
\begin{minted}{python}
def foo():
# Here would be code longer than one page
return 0
\end{minted}
\captionof{listing}{Some Text}
\egroup
\lipsum
\end{document}
另外,KOMA 定义了类似的命令
\captionof{float type}[entry]{title}
并且您不需要加载caption
包。