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'' .
Asked
Active
Viewed 343 times
5
-
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
2 Answers
6
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}

Thorsten Donig
- 46,014
4
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:

karlkoeller
- 124,410