according to other answers here (e.g. Avoid page breaks in \lstlistings, How can I ensure that a listing is not going to be split?) I have put all my listings in a minipage to avoid unwanted pagebreaks. In general I achieved what I wanted, but now I have troubles if listings (I will use a custom environment "code") are used within theorems:
\documentclass{article}
\usepackage[usenames,dvipsnames,table]{xcolor}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{listings}
\declaretheorem[qed=$\blacktriangle$]{example}
\lstnewenvironment{code}[1][]%
{%
\noindent%
\minipage{\linewidth}%
\vspace{0.5\baselineskip}%
\medskip%
\lstset{#1}}%
%\qedhere .. would be too easy
{\endminipage}
\begin{document}
\begin{example}
\begin{code}[frame=lines]
this is code
\end{code}
\end{example}
\end{document}
Which yields:
I have two problems here:
- If I have no text in the beginning (or even a paragraph is needed) the listing is next to the "Example 1." text and goes beyond the right page margins.
- The qedhere is not placed nicely. (Although its debatable how it should be)
Thank you!
Best regards, Markus


ntheorem, but for a few features). I'll give a try later. – Bernard Jul 29 '17 at 10:22