# Styling and spacing around float caption for listing

When I use the newfloat package instead of the float package there seem to be some side effects with llncs and/or listings.

Case 1: When I use the float package, the float caption of listings is not formatted correctly, but the spacing of the caption to the listing is correct, as shown in MWE #1.

Case 2: When I use the newfloat package, the float caption of listings is formatted correctly, but there is an additional spacing between the caption and the listing, as shown in MWE #2. (This spacing is not defined by the document class as can be seen at the figure environment.)

Case 3: This space is also introduced by the caption package, as can be seen in MWE #3. (just a guess, see the comments)

Case 4: Using the float option of the listings environment is also no option, as it leaves a space in the text, from where it is floating away. See MWE #4.

How can I get the same styling and spacing for the listing as for the figure?

MWE #1

\documentclass{llncs}
\usepackage{listings}

\usepackage{float}
\floatstyle{plaintop}
\newfloat{lstfloat}{tb}{lop}
\floatname{lstfloat}{Listing}

\lstset{
aboveskip=0pt,
belowskip=0pt
}

\begin{document}
\begin{lstfloat}
\caption{Code Caption}
\begin{lstlisting}
My listing here seom more text here
\end{lstlisting}
\end{lstfloat}

\begin{figure}
\caption{Text}
\centering Hello
\end{figure}
\end{document}


MWE #2

\documentclass{llncs}
\usepackage{listings}

\usepackage{newfloat}
\DeclareFloatingEnvironment[fileext=lop,placement={tb},name=Listing]{lstfloat}

\lstset{
aboveskip=0pt,
belowskip=0pt
}

\begin{document}
\begin{lstfloat}
\caption{Code Caption}
\begin{lstlisting}
My listing here seom more text here
\end{lstlisting}
\end{lstfloat}

\begin{figure}
\caption{Text}
\centering Hello
\end{figure}
\end{document}


MWE #3

\documentclass{llncs}
\usepackage{listings}

\usepackage{caption}

\usepackage{float}
\floatstyle{plaintop}
\newfloat{lstfloat}{tb}{lop}
\floatname{lstfloat}{Listing}

\lstset{
aboveskip=0pt,
belowskip=0pt
}

\begin{document}
\begin{lstfloat}
\caption{Code Caption}
\begin{lstlisting}
My listing here seom more text here
\end{lstlisting}
\end{lstfloat}

\begin{figure}
\caption{Text}
\centering Hello
\end{figure}
\end{document}


MWE #4

\documentclass{llncs}
\usepackage{lipsum}
\usepackage{listings}

\lstset{
aboveskip=0pt,
belowskip=0pt
}

\begin{document}
\lipsum[1]

\begin{lstlisting}[float=tb,caption={Code Caption}]
My listing here seom more text here
\end{lstlisting}

\lipsum[1]

\begin{figure}[tb]
\caption{Text}
\centering Hello
\end{figure}

\lipsum[1]
\end{document}


edit: add case 4 and mwe #4 edit2: move the follow up notice down

This is a follow up of my question: Make the float name bold

• The newfloat package does not load the caption package, there is no such dependency. – Axel Sommerfeldt Mar 14 at 21:49
• Sorry, I was not thorough enough. Both packages are coming from the same developer/repository. But how is this space then introduced? – white_gecko Mar 15 at 22:11
• @AxelSommerfeldt I've removed the statements about the captions package. Is it better like that? – white_gecko Mar 15 at 22:15
• Yes, the fact that the newfloat package is part of the caption package bundle can lead to false assumptions. (Maybe it would have been a better idea to make it a separate package instead.) – Axel Sommerfeldt Mar 16 at 9:29

With skip=0pt you can avoid any vertical space added by caption package.

\documentclass{llncs}
\usepackage{listings}

\usepackage{newfloat}
\DeclareFloatingEnvironment[fileext=lop,placement={tb},name=Listing]{lstfloat}
\usepackage{caption}
\captionsetup[lstfloat]{labelfont={bf},name={Listing},labelsep=period, skip=0pt}
\captionsetup[figure]{labelfont={bf},name={Fig.},labelsep=period}
\lstset{
aboveskip=0pt,
belowskip=0pt
}
\usepackage{mwe}% for testing purpose only
\begin{document}
\blindtext% for testing purpose only
\begin{lstfloat}
\caption{Code Caption}
\begin{lstlisting}
My listing here seom more text here
\end{lstlisting}
\end{lstfloat}
\blindtext% for testing purpose only
\begin{figure}
\caption{Text}
\centering Hello
\end{figure}
\blindtext% for testing purpose only
\end{document}


Here you have MWE #1 (with some dummy text) on the left and the output of my code on the right: