Generallistings | Number Listing Blocks

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
ljl16
Posts: 4
Joined: Sat Mar 17, 2012 11:43 pm

listings | Number Listing Blocks

Post by ljl16 »

Hey there,
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}
Cheers,
Last edited by Stefan Kottwitz on Fri Apr 06, 2012 1:29 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

listings | Number Listing Blocks

Post by localghost »

Take a look at Section 4.9 of the listings manual.


Thorsten
ljl16
Posts: 4
Joined: Sat Mar 17, 2012 11:43 pm

Re: listings | Number Listing Blocks

Post by ljl16 »

I just read it but I don't know how I can use parameters like "caption" or "title". Inside the lstlisting (between the begin and end) the command will be just ignored and included as text. And afterwards it will just be for the paragraph following the listing.

Any ideas?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

listings | Number Listing Blocks

Post by localghost »

These parameters are given as optional arguments to the lstlisting environment.

Code: Select all

\begin{lstlisting}[caption={Caption}]
% Listing content
\end{lstlisting}
They are all clearly explained in the mentioned section of the manual.
Post Reply