2

I have a listing as follows:

\lstdefinestyle{yamlCode} {
    numbers=left,
    language=Yaml,
    backgroundcolor={\color{lightgray!40}},
    breaklines=true,
    frame=single,
    columns=fixed
}

[...]

\begin{lstlisting}[style=yamlCode,label=YamlList,
caption=List of Maps in YAML.]
persons:
  - name:  Peter
    email: peter@example.org
  - name:  Sally
    email: sally@example.org
\end{lstlisting}

Now that listing might break after the last line of code, as can be seen in this screenshot:

page break

How can I prevent the page break after the last line? At least one line should be moved to the next page as well. Just to be clear: I do want it to break pages, however, not after the last line. How can I achieve that?

PS: Are the white lines between the code lines rendering artefacts or real? When I open the PDF in Adobe Reader and zoom in, I can still see them. Not very nice.

  • use the optional argument float. –  Oct 03 '13 at 20:18
  • @Herbert I tried several variations with float including float, float=h, th, tbh. But none of these breaks the listing at the page end. It will either be completely on the first or on the second page. Should using float page-break the listing? –  Oct 03 '13 at 20:31
  • with begin{lstlisting}[float,...] it is handled like a floatimng object and cannot have a pagebreak inside. It is moved to the other page. The only thing you can do if you want it on the same page is \enlagethispage{\normalbaselineskip} before the listing. –  Oct 03 '13 at 20:34
  • @Herbert Yes the floating does what you say, but I'd rather have a proper page break. Using enlargethispage does not seem like a viable solution as I would have to add that to every single listing were such ugly page breaks occur. If there is no other solution to that problem, I will use float=h for now. –  Oct 03 '13 at 20:39
  • You may find related info in the comments of my question – masu Oct 03 '13 at 21:23
  • @masu Thanks, I tried the proposed solutions but none of them made a difference. Did anything work for you? –  Oct 04 '13 at 07:08
  • Not yet. The only really useful info right now is the comment of egreg. I hope this will change. – masu Oct 04 '13 at 07:51

0 Answers0