3

I want to put some of my python-code in the appendix of my latex file. For that I use the following code:

\begin{minipage}[c]{0.95\textwidth}
\lstinputlisting[caption=Python script used for fitting multiple ochi-hubble-functions to the measured data, language=Python]{../Bolge/fit_best.py}
\label{pyFit}
\end{minipage}

The problem I have here is that my code is bigger than one page, but it does not make a page break when ending the page. (I am using minipage here for a proper line break in the code).
How can I improve the code so that my lstlisting will make a new page if necessary?

4
  • 4
    Don't use minipage. listings has its own keys to change the width. Apr 8 '15 at 9:40
  • 3
    BTW, package listings provides option label for a label, which can be referenced by \ref. Apr 8 '15 at 9:44
  • @UlrikeFischer Do you want to write up an answer?
    – TeXnician
    Jan 1 '18 at 9:44
  • @TeXnician well imho the question has been abandoned, but I added an answer ... Jan 1 '18 at 23:02
3

Don't use minipage. listings has its own keys to change the width e.g. linewidth, xleftmargin and more. See "5.8 Margins and line shape" in the documentation of listings.

\documentclass{article}

\usepackage{listings,lipsum}

\begin{document}
\lipsum[1]
\lstinputlisting[xrightmargin=0.05\linewidth,breaklines,breakatwhitespace,caption=inputenc]{inputenc.sty}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.