Hi,
I have a document which displays shell code with lstlisting. Now I don't have a problem with code being split due to a new page (because some code is more than a page long) but Latex also places figures in between the code. How can I solve this?
Cheers
Voga
Page Layout ⇒ Figure in lstlisting
Figure in lstlisting
Last edited by Voga on Fri Apr 08, 2011 9:57 am, edited 1 time in total.
NEW: TikZ book now 40% off at Amazon.com for a short time.

- Stefan Kottwitz
- Site Admin
- Posts: 10348
- Joined: Mon Mar 10, 2008 9:44 pm
Figure in lstlisting
Hi Voga,
welcome to the board!
You could use the \FloatBarrier command of the placeins package.
Stefan
welcome to the board!
You could use the \FloatBarrier command of the placeins package.
Stefan
LaTeX.org admin
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Figure in lstlisting
You can take a simple measure by giving appropriate placement parameters to the float environment.
Comment the optional parameters to see the difference.
Best regards and welcome to the board
Thorsten
Code: Select all
\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{xcolor}
\lstset{%
backgroundcolor=\color{gray!25},
breaklines=true,
columns=fullflexible
}
\begin{document}
\lstinputlisting{minimal.cls}
\begin{figure}[!ht]
\centering
\rule{6.4cm}{3.6cm}
\caption{Dummy figure}\label{fig:dummy}
\end{figure}
\end{document}
Best regards and welcome to the board
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Figure in lstlisting
Thanks the \FloatBarrier command works very well 
