Hello guys,
I can't find the solution for my problem:
I have some code in lstlisting. I want it to be on whole page (like it is in figures - not broken by new page). I have put it in figure tags, but then it is marked as figure, not listing.
So, how can i put listing that won't be break by new page but put on whole one / or how to name figure as listing.
Thanks,
Michal
General ⇒ lstlisting - behaviour like figure
NEW: TikZ book now 40% off at Amazon.com for a short time.

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
lstlisting - behaviour like figure
Read Section 4.3 (Space and placement, p. 26) of the listings manual to make your listings behave like a float with an according caption label.
Best regards
Thorsten¹
Best regards
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
lstlisting - behaviour like figure
Hi,
if you don't want your code to float but still want to keep it from splitting, you can use a minipage environment, as the following code suggests:
if you don't want your code to float but still want to keep it from splitting, you can use a minipage environment, as the following code suggests:
Code: Select all
\noindent\begin{minipage}{\textwidth}
\begin{lstlisting}
...
(code)
...
\end{lstlisting}
\end{minipage}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
lstlisting - behaviour like figure
Hi. Sorry for brining up an old thread, but I have a question that completely correlates to this topic.
Ok, this solution works perfectly, but is there a way that I can make this permanent, so that I don't always have to write:
but to only write:
and the rest is automatically observed?
Ok, this solution works perfectly, but is there a way that I can make this permanent, so that I don't always have to write:
Code: Select all
\noindent\begin{minipage}{\textwidth}
\begin{lstlisting}
...
\end{lstlisting}
\end{minipage}
Code: Select all
\begin{lstlisting}
...
\end{lstlisting}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Re: lstlisting - behaviour like figure
See my last reply and the link for the package manual.
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: lstlisting - behaviour like figure
Hi,
float option is actually works fine. But when I put a long code in the manuscript, it is forced to be in only one page, and then most of the code is truncated and outside of the page.
If I remove the float option, usual figures often "split" long codes. It looks ugly.
Does anyone know a workaround?
Akira
float option is actually works fine. But when I put a long code in the manuscript, it is forced to be in only one page, and then most of the code is truncated and outside of the page.
If I remove the float option, usual figures often "split" long codes. It looks ugly.
Does anyone know a workaround?
Akira