Sigh! I simply missed the forest for the trees.sommerfee wrote:[…] To make this more clear I will change "\DeclareFloatingEnvironment" to "\DeclareFloatingEnvironment offered by the newfloat package" within this paragraph.
Graphics, Figures & Tables ⇒ Multiple Listings in a single float
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Multiple Listings in a single float
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
Multiple Listings in a single float
Sure:sommerfee wrote:This should not happen. Do you have a small but complete example document for me which shows this behavior?Klausiber wrote:YFTR: The distance between the listing and its caption is a little bit wider than it is for standard floats (likefigure
). This looks weird if both type appear close to each other.
Code: Select all
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\lstset{frame=single}
\usepackage{caption}
\usepackage{newfloat}
\DeclareFloatingEnvironment[
fileext=lol,
name=Listing
]{listing}
%\captionsetup[listing]{skip=4pt}
\begin{document}
\begin{listing}
\begin{lstlisting}[gobble=6]
Listing
\end{lstlisting}
\caption{A Listing}
\end{listing}
\begin{figure}
\centering
\rule{\textwidth}{7mm}
\caption{A Figure}
\end{figure}
This just makes both floats stick to the top of the page.
\end{document}
captionsetup
line that fixes the problem for me.Multiple Listings in a single float
I finally found the problem after it also occurred (but differently) with sublistings. The subcaptions were too far from the actual listing but too close to the main caption. The source of these problems is that before and after each
lstlisting
there is a fixed amount (\medskipamount
to be precise) of vertical space. This can be prevented withCode: Select all
\lstset{aboveskip=0pt,belowskip=0pt}
