3

I recently stepped out of my comfort bounds and decided to add some Code snippets to my paper. I was able to get everything working fine and looking good, except the actual title. Everything else in my Document uses arabic, i.e. Figure 2.3, Table 4.5, etc... for some reason when I insert the Code (Using lstlisting), the published version becomes "Listing III.1: code title".

I tried using the same setup in my pre-amble as the figures, tables, and equations:

    \renewcommand\lstlistingname{\arabic{chapter}.\arabic{lstnumber}}

However, that removes the "Listing" portion and instead gives me "3.1 III.1: code title". Obviously I am not wise enough with the \renewcommand? or is there another setting I should be changing?

Here is the pre-amble I was trying to copy:

\newcommand{\updateCounters}{\renewcommand{\thefigure}{\arabic{chapter}.\arabic{figure}}%
\renewcommand{\thetable}{\arabic{chapter}.\arabic{table}}%
\renewcommand{\theequation}{\arabic{chapter}.\arabic{equation}}%

Thanks!

3

a complete example makes it easier to help!

\documentclass[openany]{book}
\usepackage{listings}
\AtBeginDocument{%
  \renewcommand\lstlistingname{My Listing}
  \renewcommand\thelstlisting{\thesection.\arabic{lstlisting}}}

\begin{document}

\lstlistoflistings

\chapter{dummy}
\section{More dummy}

\begin{lstlisting}[caption=bar]
 foo
\end{lstlisting}

\end{document}

Herbert

  • Wow, I guess I DO need to learn how to use renewcommand. I will start looking for a tutorial post haste. Thanks for the help, worked like a charm. – Biaspoint Dec 19 '10 at 15:43
  • 1
    @Mike: You should mark Herbert's answer as accepted by clicking on the outline of the checkmark next to his answer. – TH. Mar 13 '11 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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