# Change listing number separator

I am working with the listings package and trying to change the separator from the default period to a hyphen. However, I cannot seem to figure out how to.

I tried the code snippet below, but it doesn't appear to be working.

\renewcommand{\thelstlisting}{\thechapter-\arabic{lstlisting}}

\documentclass[a4paper,10pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{listings}

\begin{document}
\chapter{The Chapter}

\begin{lstlisting}[caption=The Listing Caption, language=xml]
<?xml version="1.0" encoding="utf-8">
<data>
<format/>
</data>
\end{lstlisting}

\end{document}

-

The \thelstlisting macro is defined via the \AtBeginDocument hook.

You can either re-define it after \begin{document}, or use the \AtBeginDocument hook yourself (recommended).

## Code

\documentclass[a4paper,10pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\AtBeginDocument{\renewcommand*{\thelstlisting}{\thechapter-\arabic{lstlisting}}}
\begin{document}
\chapter{The Chapter}
\begin{lstlisting}[caption=The Listing Caption, language=xml]
<?xml version="1.0" encoding="utf-8">
<data>
<format/>
</data>
\end{lstlisting}
\end{document}


## Output

-
Neat! Thank you very much for this. – lightonphiri Jan 9 '13 at 7:29