The following MWE
\documentclass{paper}
\usepackage{listings}
\begin{document}
\begin{enumerate}
\item
\begin{lstlisting}
Hello, world
\end{lstlisting}
\item
\begin{lstlisting}
Hello, world
\end{lstlisting}
\item
\begin{lstlisting}
Hello, world
\end{lstlisting}
\end{enumerate}
\end{document}
has the item numbers end up in the wrong position:
Am I doing something wrong with my item
s? Is this a bug with listings?
Best Answer
Adding a
\leavevmode
after eachlstlisting
environment solves the issue (credits). I usedetoolbox
with\AfterEndEnvironment
to have it added automatically: