I am writing a huge document and I would love to be able to number the blocks of lstlistings I'm using. I would like to use captions as in figures, just named: "Code N. (...)".
Here is a minimal working example:
Code: Select all
\documentclass[a4paper,12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{listings} %for codes
\usepackage{textcomp}
% %For the color of the source codes:
\usepackage{color}
\lstset{
language=[Visual]C++,
keywordstyle=\bfseries\ttfamily\color[rgb]{0.133,0.545,0.133},
identifierstyle=\ttfamily,
commentstyle=\color[rgb]{0,0,1},
stringstyle=\ttfamily\color[rgb]{1,0.1,0.9},
showstringspaces=false,
basicstyle=\scriptsize,%\small,
% numberstyle=\footnotesize,
% numbers=left,
stepnumber=1,
numbersep=10pt,
tabsize=2,
breaklines=true,
% prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
breakatwhitespace=false,
aboveskip={1.5\baselineskip},
columns=fixed,
upquote=true,
extendedchars=true,
frame=single,
}
\begin{document}
BLABLABLABLABLA
\begin{lstlisting}
roscreate-pkg [package_name] [depend1] [depend2] [depend3]
\end{lstlisting}
BLABLABLABLABLA
\begin{lstlisting}
//Change directory to the desired path for the package
cd ~/ros_workspace
//Creating the package
roscreate-pkg beginner_tutorials std_msgs rospy roscpp
\end{lstlisting}
\end{document}