Hallo zusammen,
ich habe mithilfe von \lstinputlisting einen mehrseitigen Python Quellcode eingefügt. Das ganze funktioniert auch ohne Probleme.
Den Code hab ich im Anhang meiner Dokumentes, sobald ich weitere Anhänge hinzufüge, werden diese Anhänge zwischen meinen Quellcode geschoben.
Sieht dann so aus:
1. Seite Quellcode
2. Seite Weiterer Anhang
3. Seite restlicher Quellcode
Kann ich irgendwie verhindern das die Seiten dazwischen geschoben werden?
Ich nehme mal an das man den Code in eine Umgebung packen kann, aber die die ich bisher versucht habe, haben versucht den Code auf einer Seite darzustellen, was wegen seiner länge nicht möglich ist.
Vielen Dank!
Mehrseitiger Quellcode wird unterbrochen
Ich vermute, du hast für das Listing Option float gesetzt. Entferne diese. Wenn ich mich irre, dann mach bitte ein Minimalbeispiel. Das solltest du bei Fragen grundsätzlich tun, damit wir nicht auf Spekulationen angewiesen sind, sondern das Problem reproduzieren und unsere Ideen testen können.
Dann reich ich hier mal mein Minimalbeispiel nach, es ist etwas länger geworden, da der Code ja auch irgendwie in das Beispiel musste :
In meinem ursprünglichen Dokument füge ich den Code über \lstinputlisting[language=Python]{Test.py} in das Dokument ein, falls das einen Unterschied macht.
\documentclass[12pt]{article} \usepackage[english]{babel} \usepackage[utf8x]{inputenc} \usepackage{amsmath} \usepackage{tikz} \usepackage{mwe} \usepackage{listings} \lstset{numbers=left, numberstyle=\tiny, numbersep=5pt, breaklines=true, showstringspaces=false, frame=l , xleftmargin=15pt, xrightmargin=15pt, basicstyle=\ttfamily\small, stepnumber=1, } \begin{document} \section{Anhang} \begin{figure} \includegraphics[width=15cm,height=18cm]{example-image} \end{figure} %\lstinputlisting[language=Python]{Test.py} \begin{lstlisting} print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") \end{lstlisting} \end{document}
Wenn Du nicht willst, dass die Abbildung gleitet, dann verwende keine figure-Umgebung. Sorge außerdem dafür, dass sie keine overfull oder underfull \hbox oder \vbox verursacht:
Natürlich ginge auch wäre aber ein wenig von hinten durch die Brust ins Knie.
\documentclass[12pt]{article} \usepackage[english]{babel} \usepackage[utf8]{inputenc}% utf8x bereitet mit diversen Paketen Probleme und % ist selten sinnvoll \usepackage{placeins} \usepackage{mwe} \usepackage{listings} \lstset{numbers=left, numberstyle=\tiny, numbersep=5pt, breaklines=true, showstringspaces=false, frame=l , xleftmargin=15pt, xrightmargin=15pt, basicstyle=\ttfamily\small, stepnumber=1, } \begin{document} \FloatBarrier \section{Anhang} \includegraphics[width=\textwidth,height=.92\textheight]{example-image} %\lstinputlisting[language=Python]{Test.py} \begin{lstlisting} print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") \end{lstlisting} \end{document}
\documentclass[12pt]{article} \usepackage[english]{babel} \usepackage[utf8]{inputenc}% utf8x bereitet mit diversen Paketen Probleme und % ist selten sinnvoll \usepackage{placeins} \usepackage{mwe} \usepackage{listings} \lstset{numbers=left, numberstyle=\tiny, numbersep=5pt, breaklines=true, showstringspaces=false, frame=l , xleftmargin=15pt, xrightmargin=15pt, basicstyle=\ttfamily\small, stepnumber=1, } \begin{document} \section{Anhang} \begin{figure}[!htp] \includegraphics[width=\textwidth,height=.92\textheight]{example-image} \end{figure} \FloatBarrier %\lstinputlisting[language=Python]{Test.py} \begin{lstlisting} print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") print("This line will be printed.") \end{lstlisting} \end{document}