[Tex/LaTex] Change caption style of listings package without “caption” package

captionslistings

Is there a way to change style of a caption in listings without the caption package (make it smaller and non-bold)? I am using \lstnewenvironment to create my own customized environment and then use listings via this new environment.

I tried to do it with the caption package with \captionsetup[lstlisting]{font={scriptsize,tt}} and it worked, but the problem is that I cannot use caption package as it messes up captions in the rest of the document (as soon as I "include" it), and I have to use predefined class.

Thank you for your help!

(EDIT) Class: http://www.acm.org/sigs/publications/sig-alternate.cls

(EDIT) MEW:

\documentclass{sig-alternate}

%\usepackage{caption}
\usepackage{listings}

\begin{document}

\title{The Title}

\numberofauthors{1}
\author{
\alignauthor
       John Doe\\
       \affaddr{Lorem ispum}\\
       \affaddr{Lorem ispum}\\
       \affaddr{Lorem ipsum}\\
       \email{john.doe@example.com}
}
\date{30 July 1999}
\maketitle



\lstnewenvironment{mycode}[1][]
{
  \minipage[b]{0.3\textwidth}
  \lstset{
    captionpos=b,
    language=C,
    numbers=left,
    basicstyle=\tiny\ttfamily,
    columns=fullflexible,
    showstringspaces=false,
    numbersep=3pt,
    #1
  }
}
{
  \endminipage
}
%\captionsetup[lstlisting]{font={small,tt}}

\begin{mycode}[title=Awesome C program,label=code:AwesomeC]
  int main(int argc, char* argv[]) {
    return 0;
  }
\end{mycode}

If I use "caption" package, caption of the figure changes style (it is no longer bold). Otherwise I cannot change caption of the code...

\begin{figure}
  \centering
  This is a figure
  \caption{Caption of the figure}  
\end{figure}

\end{document}

Best Answer

One possibility is to use the caption package, but loading it in the form

\usepackage[font=bf,skip=\baselineskip]{caption}

so as to preserve the default caption style implemented by the sig-alternate document class. Then you can invoke

\captionsetup[lstlisting]{font={small,tt}}

to change the listings caption format. A complete example:

\documentclass{sig-alternate}
\usepackage{listings}
\usepackage[font=bf,skip=\baselineskip]{caption}
\captionsetup[lstlisting]{font={small,tt}}

\lstnewenvironment{mycode}[1][]
{
  \minipage[b]{0.3\textwidth}
  \lstset{
    captionpos=b,
    language=C,
    numbers=left,
    basicstyle=\tiny\ttfamily,
    columns=fullflexible,
    showstringspaces=false,
    numbersep=3pt,
    #1
  }
}
{
  \endminipage
}

\begin{document}

\title{The Title}
\numberofauthors{1}
\author{
\alignauthor
       John Doe\\
       \affaddr{Lorem ispum}\\
       \affaddr{Lorem ispum}\\
       \affaddr{Lorem ipsum}\\
       \email{john.doe@example.com}
}
\date{30 July 1999}
\maketitle

\begin{mycode}[title=Awesome C program,label=code:AwesomeC]
  int main(int argc, char* argv[]) {
    return 0;
  }
\end{mycode}

\begin{figure}
  \centering
  This is a figure
  \caption{Caption of the figure}  
\end{figure}

\begin{table}
  \centering
  This is a table
  \caption{Caption of the table}  
\end{table}

\end{document}

enter image description here

Related Question