I'm trying to avoid page breaks in my lstlisting
(seen in section 0.0.2) I know I can remedy this by floating my lstlisting
, but it adds some unwanted white space (seen in section 0.0.1).
Is there an alternative to float
so that my lstlisting
will not break across pages?
OR
Can I configure float
to eliminate the white space so it looks identical to how it is when not in a float
*I apologize for the cruft in my MWE. I'm just trying to use this in a much larger document, so I'd rather keep it as close to it as possible.
\documentclass{article}
% New commands
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\newcommand{\superscript}[1]{\ensuremath{^{\textrm{#1}}}}
% Modified commands
\renewcommand*\abstractname{Revision History}
%%%%% Packages and configuration %%%%%
\usepackage[firstpage]{draftwatermark}
\SetWatermarkText{\textsc{Confidential}}
\SetWatermarkScale{4}
\SetWatermarkColor[gray]{0.9}
%\usepackage{fancyhdr}
%\pagestyle{fancy}
%\fancyhf{} % clear all fields
%\fancyfoot[LE,CO]{\thepage} % page number in "outer" position of footer line
%\fancyfoot[RE,LO]{Message of the day} % other info in "inner" position of footer line
\usepackage{tabularx}
\usepackage[table]{xcolor}
\definecolor{dark-red}{rgb}{0.4,0.15,0.15}
\definecolor{dark-blue}{rgb}{0.15,0.15,0.4}
\definecolor{medium-blue}{rgb}{0,0,0.5}
\definecolor{light-grey}{gray}{0.8}
\usepackage[hidelinks]{hyperref}% keep at end
\hypersetup{
colorlinks,
linkcolor={black},
citecolor={dark-blue},
urlcolor={medium-blue}
}
%\usepackage[cm]{fullpage}
%\usepackage[letterpaper, top=0.7in, bottom=0.9in, left=0.7in, right=0.7in, showframe]{geometry}
\usepackage[margin=0.5in]{geometry}
%\usepackage{color}
\usepackage{listings}
\lstset{ %
language=C, % choose the language of the code
basicstyle=\footnotesize, % the size of the fonts that are used for the code
%numbers=left, % where to put the line-numbers
%numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers
%stepnumber=1, % the step between two line-numbers. If it is 1 each line will be numbered
%numbersep=5pt, % how far the line-numbers are from the code
%backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false, % show spaces adding particular underscores
showstringspaces=false, % underline spaces within strings
showtabs=false, % show tabs within strings adding particular underscores
%frame=single, % adds a frame around the code
tabsize=4, % sets default tabsize to 4 spaces
captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
%escapeinside={\%*}{*)} % if you want to add a comment within your code
}
\usepackage{mdwlist}
\usepackage{underscore}
\usepackage{tikz}
\usepackage{float}
\usepackage{lipsum}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{etex}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@afterheading}%
{\clubpenalty \@M}{\clubpenalties 2 \@M \@M }{}{}
\patchcmd{\@afterheading}%
{\clubpenalty \@clubpenalty}{\clubpenalties 1 \@clubpenalty }{}{}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\lipsum[1-8]
\subsubsection{Lorem Ipsum Dolomite}\leavevmode
\begin{lstlisting}
void abc_defgh_ijklmn_stuff * const ( void );
\end{lstlisting}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc id sapien eget magna tempus ornare vitae ut dolor. Donec pharetra diam vitae erat sollicitudin a blandit sapien blandit. Nam ligula metus, imperdiet ut accumsan non, tincidunt id a.
\subsubsection{abcde}
\begin{lstlisting}
static boolean abcde
(
abc_defg_hijk * const lm
);
\end{lstlisting}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc id sapien eget magna tempus ornare vitae ut dolor. Donec pharetra diam vitae erat sollicitudin a blandit sapien blandit. Nam ligula metus, imperdiet ut accumsan non, tincidunt id a.\\
\end{document}
\newpage
around every time I update it.