Page Layout ⇒ Figure in lstlisting
Figure in lstlisting
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
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
- Stefan Kottwitz
- Site Admin
- Posts: 10326
- Joined: Mon Mar 10, 2008 9:44 pm
Figure in lstlisting
welcome to the board!
You could use the \FloatBarrier command of the placeins package.
Stefan
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Figure in lstlisting
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
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Figure in lstlisting
