我正在使用minted
,但不知何故,铸造环境和周围文本或(子)部分之间的距离不一样,并且与正常间距相差太大。
这是我的 MWE:
\documentclass{article}
\usepackage{minted}
\newminted{py}{bgcolor=gray!5, breaklines = true,gobble=0, fontfamily=courier}
\newmintinline[picode]{python}{}
\newcounter{ea}[subsubsection]
\newenvironment{ea}[1][]{\refstepcounter{ea}\par\medskip
\noindent \textit{Example~\theea. #1} \rmfamily}{\medskip}
\begin{document}
\section{Sample}
\subsection{Sample 1}
The code goes here:
\begin{ea}
\begin{pycode}
440//11
40
117//5
23
\end{pycode}
\end{ea}
%THIS DISTANCE IS TOO MUCH
\subsection{range()}
\begin{ea}
\begin{pycode}
for i in range(2):
print(i)
#Output
0
1
\end{pycode}
\end{ea}
Some text goes here
\subsection{Unknown}
\end{document}
图片如下:
无论有没有环境 ea 后面的文本,它们之间的距离似乎都很大。我该如何解决这个问题?我尝试设置,framsep = 2pt
但framesep=2mm
没有成功。
答案1
你不想要\medskip
,而是\addvspace{\medskipamount}
。参见\addvspace 和 \vspace 之间的区别
\documentclass{article}
\usepackage{minted}
\newminted{py}{bgcolor=gray!5, breaklines = true,gobble=0, fontfamily=courier}
\newmintinline[picode]{python}{}
\newcounter{ea}[subsubsection]
\newenvironment{ea}[1][]{\refstepcounter{ea}\par\addvspace{\medskipamount}
\noindent \textit{Example~\theea. #1} \rmfamily}{\par\addvspace{\medskipamount}}
\begin{document}
\section{Sample}
\subsection{Sample 1}
The code goes here:
\begin{ea}
\begin{pycode}
440//11
40
117//5
23
\end{pycode}
\end{ea}
\subsection{range()}
\begin{ea}
\begin{pycode}
for i in range(2):
print(i)
#Output
0
1
\end{pycode}
\end{ea}
Some text goes here
\subsection{Unknown}
\end{document}
不要抱怨章节标题前的空间较大,因为这是由于标题中的字体较大。
不过,我会使用更标准的方法。
\documentclass{article}
\usepackage{minted}
\usepackage{amsthm}
\newminted{py}{bgcolor=gray!5, breaklines = true,gobble=0, fontfamily=courier}
\AddToHook{env/pycode/before}{\leavevmode\vspace*{-\baselineskip}}
\newmintinline[picode]{python}{}
\newtheoremstyle{example}
{\topsep} % ABOVESPACE
{\topsep} % BELOWSPACE
{\normalfont} % BODYFONT
{0pt} % INDENT (empty value is the same as 0pt)
{\itshape} % HEADFONT
{.} % HEADPUNCT
{\newline} % HEADSPACE
{\thmname{#1}\thmnumber{ #2}\thmnote{\/{\normalfont\space(#3)}}} % CUSTOM-HEAD-SPEC
\theoremstyle{example}
\newtheorem{ea}{Example}[subsection]
\begin{document}
\section{Sample}
\subsection{Sample 1}
The code goes here:
\begin{ea}
\begin{pycode}
440//11
40
117//5
23
\end{pycode}
\end{ea}
\subsection{range()}
\begin{ea}[Interesting]
\begin{pycode}
for i in range(2):
print(i)
#Output
0
1
\end{pycode}
\end{ea}
Some text goes here
\subsection{Unknown}
Some text
\begin{pycode}
for i in range(2):
print(i)
#Output
0
1
\end{pycode}
\end{document}