I am trying to include a python code (within a colored mdframed
box) into my tex file. However, I noticed that when I use the geometry package simultaniously with mdframed and fancyhdr, two things happen:
1) automatic line breaking within mdframed boxes doesn't work anymore 2) the top and bottom margins are set to a value around 1cm (no matter what value I set)
When I remove the geometry package, the line breaking works, but the (default) margins are again way too large.
Here my code:
\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}
Now does anyone have a solution for this? How can I get automatic line breaking AND a 2.54cm margin (while using fancyhdr
)?
Thanks a lot!
PS: the anysize package (used to set the margins) produces the same output.
fancyhdr
has nothing to do with this. You're using the wrong tool here. You should uselistings
and a wrapper environmentgeometry
is that the margins just that large that line breaking works withinmdframed
. That's pure coincidence. Increasing tomargin=3cm
will also provide linebreaking, but of course, that value is too large for you\texttt
- it does not break with that font