Mehrseitiger Quellcode wird unterbrochen

Schriftbild, Absätze und Auflistungen einstellen


Gast

Mehrseitiger Quellcode wird unterbrochen

Beitrag von Gast »

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!

Gast

Beitrag von Gast »

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.

Gast

Beitrag von Gast »

Dann reich ich hier mal mein Minimalbeispiel nach, es ist etwas länger geworden, da der Code ja auch irgendwie in das Beispiel musste :D :
\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}
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.

Gast

Beitrag von Gast »

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:
\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}
Natürlich ginge auch
\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}
wäre aber ein wenig von hinten durch die Brust ins Knie.

Gast

Beitrag von Gast »

Habe es jetzt gelöst indem ich die Gleitumgebungen entfernt habe.

Das mit dem overfull war nur weil ich das MB nicht nochmal überprüft habe, ebenso das uft8x, die Probleme habe ich in meinem eigentlichen Dokument nicht - dennoch danke für die Hinweise.

Antworten