Posts

Showing posts with the label Listings

Avoid Page Breaks In \lstlistings

Answer : Wrapping the lstlisting inside a minipage (of width \linewidth ) boxes the content making it unbreakable and avoids breaking across the page boundary: ... \begin{minipage}{\linewidth} \begin{lstlisting} static boolean abcde ( abc_defg_hijk * const lm ); \end{lstlisting} \end{minipage} ... Depending on the location of usage, you may have to prepend the environment with \noindent to avoid any paragraph indentation. A somewhat similar approach is followed if you load the float package and use ... \begin{lstlisting}[float,floatplacement=H] static boolean abcde ( abc_defg_hijk * const lm ); \end{lstlisting} ... More on the float placement H is discussed in How to influence the position of float environments like figure and table in LaTeX? I'm using version 1.5 (2013) of the listings package. I use lstinputlisting to include the code from the file, and I just put float inside the options of the environment. It works fine. For example, this goes in my ...