![parskip=half 选项在 captionof 之后被忽略](https://linux22.com/image/304263/parskip%3Dhalf%20%E9%80%89%E9%A1%B9%E5%9C%A8%20captionof%20%E4%B9%8B%E5%90%8E%E8%A2%AB%E5%BF%BD%E7%95%A5.png)
使用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
包。