使用幾何套件的 mdframed 中沒有斷行

使用幾何套件的 mdframed 中沒有斷行

我試圖將 python 程式碼(在彩色mdframed框中)包含到我的 tex 檔案中。但是,我注意到當我使用幾何學同時打包多幀奇特博士,發生兩件事:

1) mdframed 框中的自動換行不再起作用 2) 頂部和底部邊距設定為 1cm 左右的值(無論我設定什麼值)

當我刪除幾何學包中,換行有效,但(預設)邊距再次太大。

這是我的程式碼:

\documentclass[12pt, a4paper, titlepage]{article}

\usepackage[dvipsnames]{xcolor}
\usepackage[ngerman]{babel}

\usepackage[margin=2.54cm]{geometry}
\usepackage{fancyhdr}
\usepackage{mdframed}

\pagestyle{fancy}

\newcommand{\gbx}[1]{
\begin{mdframed}[backgroundcolor=black!20, leftmargin=0, rightmargin=0, innertopmargin=10pt, innerbottommargin=10pt, topline=false, bottomline=false, rightline=false, leftline=false]
#1
\end{mdframed}
}

\begin{document}

\gbx{\texttt{import numpy as np\\
import matplotlib.pyplot as plt\\\\
verteilung = np.random.normal(0., 1., 1000000)\\
bins = len(verteilung)/15000\\\\
fig = plt.figure()\\
ax = fig.add\_subplot(111)\\
plt.hist(verteilung, bins = bins, normed = 1, color = 'blue', label = 'Zufallswerte')\\
plt.xlabel('Wert')\\
plt.ylabel('Anzahl')\\
ax.annotate('Maximum', xy = (0, 0.4), xytext = (-0.75, 0.42))\\
plt.legend()\\
plt.grid()\\
plt.savefig('histo.svg', format='svg', dpi=1000)\\
plt.show()
}}

\end{document}

現在有人有解決方案嗎?如何獲得自動換行和 2.54cm 邊距(使用時fancyhdr)?

多謝!

PS: 的任何尺寸包(用於設定邊距)產生相同的輸出。

相關內容