在这里,我发现了一个与水平线类似的问题,这个答案我不太理解,但我可以用它来解决我的问题:
我正在寻找行号分隔规则当。。。的时候框架规则有已经到过延长包含行号(如果只使用 listings 包就可以实现就好了)。请参见以下示例:
最小工作示例:
\documentclass{report}
\usepackage{xcolor}
\definecolor{halfgray}{gray}{0.55}
\definecolor{ipython_frame}{RGB}{207, 207, 207}
\usepackage{listings}
\lstdefinelanguage{iPython}{
commentstyle=\color{cyan}\ttfamily,
stringstyle=\color{red}\ttfamily,
keepspaces=true,
showspaces=false,
showstringspaces=false,
%
rulecolor=\color{ipython_frame},
frame=single,
frameround={t}{t}{t}{t},
framexleftmargin=6mm,
numbers=left,
numberstyle=\tiny\color{halfgray},
%
basicstyle=\scriptsize\ttfamily,
keywordstyle=\color{green}\ttfamily,
}
\begin{document}
\begin{lstlisting}[language=iPython]
import math
import numpy as np
from lib.analytical import csa
sin2_theta = np.sin(theta)**2
+= -= *= /= + - * / ? < > & % == <=
# += -= *= /= + - * / ? < > & % == <=
def test(a=100, b=True):
<= >= == 2 + 3j * 7e-3
\end{lstlisting}
\end{document}
答案1
相当黑客解决方案是使用彩色盒子边框,以便您可以使用frame
规则列表。为包含和代码Tcolorbox
的框提供库。下面是一个最小设置,但您有很大的改进空间,因为es 是高度可定制的:listings
minted
tcolorbox
\documentclass{report}
\usepackage{xcolor}
\definecolor{halfgray}{gray}{0.55}
\definecolor{ipython_frame}{RGB}{207, 207, 207}
\usepackage{tcolorbox}
\tcbuselibrary{listings}%
\usepackage{lipsum}
\usepackage{listings}
\tcbset{listing engine={listings}}
\lstdefinelanguage[]{iPython}[]{python}{
commentstyle=\color{cyan}\ttfamily,
stringstyle=\color{red}\ttfamily,
keepspaces=true,
showspaces=false,
showstringspaces=false,
%
rulecolor=\color{ipython_frame},
frame=l,
numbers=left,
numberstyle=\tiny\color{halfgray},
xleftmargin={0.75cm},
%
basicstyle=\scriptsize\ttfamily,
keywordstyle=\color{green}\ttfamily,
}
\begin{document}
\lipsum[1]
\begin{tcblisting}{boxrule=1pt, listing only,listing options={language=iPython}}
import math
import numpy as np
from lib.analytical import csa
sin2_theta = np.sin(theta)**2
+= -= *= /= + - * / ? < > & % == <=
# += -= *= /= + - * / ? < > & % == <=
def test(a=100, b=True):
<= >= == 2 + 3j * 7e-3
\end{tcblisting}
\lipsum[2]
\end{document}
这将给你这个:
关于在列表中定义新语言的简要说明:您可以使用新语言的基本方言,这样您就不需要从头开始定义所有关键字。
\lstdefinelanguage
[[hdialecti]]{hlanguagei}
[[hbase dialecti]{hand base languagei}]
{hkey=value listi}
[[hlist of required aspects (keywordcomments,texcs,etc.)]]
因此\lstdefinelanguage[]{iPython}[]{python}
。