Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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'' .

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

2 Answers 2

up vote 6 down vote accepted

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}

enter image description here

share|improve this answer
    
Great! Thank you very vell –  czsan Feb 16 at 11:47

Without any additional package, add the following lines in your preamble:

\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:

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.