General ⇒ lstlisting - behaviour like figure
lstlisting - behaviour like figure
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
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
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
lstlisting - behaviour like figure
Best regards
Thorsten¹
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
lstlisting - behaviour like figure
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}
lstlisting - behaviour like figure
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
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: lstlisting - behaviour like figure
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