1

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
}
  • 2
    Welcome to TeX.SX! What do you mean by "automatic signature"? – egreg Jan 26 '14 at 22:11
  • 1
    Maybe some kind of caption would do what you want? – Geoff Pointer Jan 26 '14 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 '14 at 23:46
  • Maybe this link will help. – Geoff Pointer Jan 30 '14 at 12:41
0

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

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.