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
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- 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