# How can I reverse the caption numbering in listing

How can I make a reverse numbered caption with listings? So the package makes ''Listing 1.1'' style captions but I need it in form ''1.1 Listing'' .

-
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  karlkoeller Feb 16 '14 at 11:58
Remember that you can accept one of the answers below, since both seem to solve your problem. –  karlkoeller Feb 19 '14 at 17:04

Use the »caption« package to declare a new label format. Of course you can do other additional customizations in this way.

\documentclass[11pt]{report}
\usepackage[T1]{fontenc}

\usepackage{caption}
\DeclareCaptionLabelFormat{reverse}{#2 #1}
\captionsetup[lstlisting]{labelformat=reverse}

\usepackage{listings}

\begin{document}
\chapter{Foo}

\section{Bar}
\begin{lstlisting}[
gobble=6,
frame=single,
caption={Useless code},
label=useless
]
for i:=maxint to 0 do
begin
{ do nothing }
end;
\end{lstlisting}
\end{document}

-
Great! Thank you very vell –  czsan Feb 16 '14 at 11:47

\makeatletter
\renewcommand\fnum@lstlisting{%
\ifx\lst@@caption\@empty\else\thelstlisting~\fi%
\lstlistingname}%
\makeatother

MWE:

\documentclass{report}
\usepackage{listings}

\makeatletter
\renewcommand\fnum@lstlisting{%
\ifx\lst@@caption\@empty\else\thelstlisting~\fi%
\lstlistingname}%
\makeatother

\begin{document}
\chapter{Test}
\begin{lstlisting}[frame=single,caption={foo}]
Welcome to TeX.SX
\end{lstlisting}
\end{document}

Output:

-