![使用 minted 包破坏了我的段落缩进](https://linux22.com/image/419180/%E4%BD%BF%E7%94%A8%20minted%20%E5%8C%85%E7%A0%B4%E5%9D%8F%E4%BA%86%E6%88%91%E7%9A%84%E6%AE%B5%E8%90%BD%E7%BC%A9%E8%BF%9B.png)
我正在使用 minted 包来编写一篇论文,一切都运行良好,编译时没有错误,只是第一次使用后,\begin{minted}{csharp}
通常的段落缩进不再起作用。在此之前,每当我在段落之间留一个空行时,下一段就会自动缩进(应该是这样的),但在第一次出现 minted 之后,同样的事情不会产生缩进。这是我的代码的样子和它产生的结果:
\documentclass{article}
\usepackage{subcaption}
\usepackage{float}
\usepackage{minted}
\usepackage{listings}
\usemintedstyle{friendly}
\setminted[csharp]{
breaklines,
mathescape,
obeytabs=true,
tabsize=4,
linenos,
numbersep=5pt,
frame=single,
numbersep=5pt,
xleftmargin=0pt,
}
\newcommand{\lstCapLbl}[2]{%
\vspace{-0.9\baselineskip}
\captionof{listing}{#1\label{lst:#2}}
\vspace{0.9\baselineskip}
}
\begin{document}
\section{Paragraph}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\begin{minted}{csharp}
AudioSource audio = gameObject.GetComponent<AudioSource>();
\end{minted}
\lstCapLbl{Example Code Showing the Use of GetComponent}{}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{document}
这段代码之后,使用\indent
手动缩进段落也不起作用。有人知道是什么原因造成的吗?
更新:我发现该\lstCapLbl
命令导致了该问题,有什么想法可以在不破坏以下段落的情况下创建这样的标题吗?
答案1
切勿忽略警告。您的示例文档生成以下内容:
Package caption Warning: \captionsetup{type*=...} or \captionof
(caption) outside box or environment on input line 39.
See the caption package documentation for explanation.
这是在警告你,你已经\captionof
在外层使用了它,而这正是导致问题的原因。
如果将其放置在环境中,则会出现警告并且以下文本会缩进。
您可以定义自定义环境,但我只empty
在这里使用:
\begin{empty}
\begin{minted}{csharp}
AudioSource audio = gameObject.GetComponent<AudioSource>();
\end{minted}
\lstCapLbl{Example Code Showing the Use of GetComponent}{}
\end{empty}
答案2
您应使用newfloat
选项minted
,以确保获得更好的支持caption
。
\documentclass{article}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[newfloat]{minted}
\usemintedstyle{friendly}
\setminted[csharp]{
breaklines,
mathescape,
obeytabs=true,
tabsize=4,
linenos,
numbersep=5pt,
frame=single,
numbersep=5pt,
xleftmargin=0pt,
}
\captionsetup[listing]{position=bottom,skip=-0.5\baselineskip}
\begin{document}
\section{Paragraph}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
\begin{listing}[!htp]
\begin{minted}{csharp}
AudioSource audio = gameObject.GetComponent<AudioSource>();
\end{minted}
\caption{Example Code Showing the Use of GetComponent\label{show}}
\end{listing}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
\end{document}