Page LayoutFigure in lstlisting

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
Voga
Posts: 2
Joined: Thu Apr 07, 2011 5:15 pm

Figure in lstlisting

Post by Voga »

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
Last edited by Voga on Fri Apr 08, 2011 9:57 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

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

Post by Stefan Kottwitz »

Hi Voga,

welcome to the board!

You could use the \FloatBarrier command of the placeins package.

Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Figure in lstlisting

Post by localghost »

You can take a simple measure by giving appropriate placement parameters to the float environment.

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}
Comment the optional parameters to see the difference.


Best regards and welcome to the board
Thorsten
Voga
Posts: 2
Joined: Thu Apr 07, 2011 5:15 pm

Re: Figure in lstlisting

Post by Voga »

Thanks the \FloatBarrier command works very well :)
Post Reply