[Tex/LaTex] Line numbers in pseudocode in figures – using lineno in figures

line-numberingpseudocode

can someone show an example how to obtain line numbers in the alltt environment in figures, possibly using the lineno package?

I've tried:

\begin{figure}[h]
\begin{alltt}
{\linenumbers
def insert(k, v)
  // ... pseudocode
}
\end{alltt}
\caption{Basic operations I}
\end{figure}

but that, or using the linenumbers environment, doesn't do anything.
The code above doesn't work even if the alltt environment is removed – there are no line numbers if the text is within a figure.

Is there any way to obtain line numbering in figures?

Thank you.

Best Answer

Figured it out - one should use the \internallinenumbers directive, like this:

\begin{figure}
\begin{alltt}
{\footnotesize{\internallinenumbers
def insert(k, v)
  // ...
}}
\end{alltt}
\end{figure}