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 put automatic signature below my code listings. Now I put my code listings like this:

\begin{lstlisting}
MY CODE
\end{lstlisting}

Settings of listings:

    \usepackage{color}
\definecolor{bluekeywords}{rgb}{0.13,0.13,1}
\definecolor{greencomments}{rgb}{0,0.5,0}
\definecolor{redstrings}{rgb}{0.9,0,0}

\usepackage{listings}
\lstset{language=[Sharp]C,
  showspaces=false,
  showtabs=false,
  breaklines=true,
  numbers=left,
  frame=single,
  showstringspaces=false,
  breakatwhitespace=true,
  escapeinside={(*@}{@*)},
  commentstyle=\color{greencomments},
  keywordstyle=\color{bluekeywords},
  stringstyle=\color{redstrings},
  basicstyle=\ttfamily
}
share|improve this question
2  
Welcome to TeX.SX! What do you mean by "automatic signature"? –  egreg Jan 26 at 22:11
1  
Maybe some kind of caption would do what you want? –  Geoff Pointer Jan 26 at 22:15
    
Yes, I want to make caption below listing and finally I would like to make table of contents - listings –  Aclber Jan 26 at 23:46
    
Maybe this link will help. –  Geoff Pointer Jan 30 at 12:41

1 Answer 1

up vote 1 down vote accepted

You can use the caption key to obtain the captions; use captionpos=b so that the captions appear below the listing (the default position is above). The command \lstlistoflistings gives you a list of all listings for which you declared a caption.

\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}

\definecolor{bluekeywords}{rgb}{0.13,0.13,1}
\definecolor{greencomments}{rgb}{0,0.5,0}
\definecolor{redstrings}{rgb}{0.9,0,0}

\usepackage{listings}
\lstset{language=[Sharp]C,
  showspaces=false,
  showtabs=false,
  breaklines=true,
  numbers=left,
  frame=single,
  showstringspaces=false,
  breakatwhitespace=true,
  escapeinside={(*@}{@*)},
  commentstyle=\color{greencomments},
  keywordstyle=\color{bluekeywords},
  stringstyle=\color{redstrings},
  basicstyle=\ttfamily,
  captionpos=b
}

\begin{document}

\lstlistoflistings

\begin{lstlisting}[caption={this is some description of the first listing}]
MY CODE
\end{lstlisting}

\begin{lstlisting}[caption={this is some description of the second listing}]
MY CODE
\end{lstlisting}

\begin{lstlisting}[caption={this is some description of the third listing}]
MY CODE
\end{lstlisting}

\end{document}

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.