I would like to numerate listings according to sections. If the listing is in subsection then it should have subsection numbers.
This example is very good and I'm using it for some other numbering, but it gives me error because I can't seem to guess the parameter for renewcommand
\renewcommand{\thelstlistingname}{%
\ifnum\value{subsection}=0
\thesection.\arabic{lstlistingname}%
\else
\ifnum\value{subsubsection}=0
\thesubsection.\arabic{lstlistingname}%
\else
\thesubsubsection.\arabic{lstlistingname}%
\fi
\fi
}
This is the MWE
\documentclass[11pt]{article}
\usepackage{listings}
\renewcommand{\lstlistingname}{Pseudokod}
\begin{document}
\section{Section}
\subsection{Subsection}
\begin{lstlisting}[caption=Pseudokod za algoritam segmentacije slike u boji.]
...
ucitaj sliku
ucitaj zeljeni prag ili pragove za segmentaciju
podijeli sliku na kanale //ako je u pitanju RGB slika podijela je na R, G i B kanal boje
primjeni prag na svakom kanalu
AND operacija na kanalima
prikazi sliku
...
\end{lstlisting}
\end{document}
Since the listing is in section 1.1 I would like it to be numbered like 1.1.1. Next listing in that section would be 1.1.2, etc.
\thelstlisting? – Ludovic C. Sep 21 '13 at 15:57