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.

I am using the listings package to display code in my document. is it possible to add the listings to the List of Figures. Instead of Listing, there should be Figure in the caption and it should share the same counter as the figures.

share|improve this question
add comment

1 Answer

The easiest way to obtain this is to insert your listing directly into a figure environment:

enter image description here

\documentclass{article}
\usepackage{listings}% http://ctan.org/pkg/listings
\lstset{% general command to set parameter(s)
  basicstyle=\small, % print whole listing small
  keywordstyle=\color{black}\bfseries\underbar, % underlined bold black keywords
  identifierstyle=, % nothing happens
  commentstyle=\color{white}, % white comments
  stringstyle=\ttfamily, % typewriter type for strings
  showstringspaces=false} % no special string spaces
\begin{document}
\listoffigures
\begin{figure}
  \rule{150pt}{100pt}%
  \caption{A normal figure}
\end{figure}
\begin{figure}
\begin{lstlisting}
for i:=maxint to 0 do
begin
{ do nothing }
end;
Write(’Case insensitive ’);
WritE(’Pascal keywords.’);
\end{lstlisting}
\caption{This is a listing}
\end{figure}
\end{document}

The above listing example was taken from the listings documentation (section 1.3 Figure out the appearance, p 5).

share|improve this answer
    
the problem now is that the listings cant start on one page and end on the next, cause the figure dont get split like the listings –  Cheetah Jul 10 '12 at 22:06
    
@Cheetah: That's true - floats are limited to a "moving box" that has to fit within the page, otherwise you run the risk of a breakable float being split over more than two pages. There are ways to address that and would most likely require you to drop the floating capability of the listing (and also fall outside the scope of this question). Please post it as a fresh one using the "Ask Question" link above. Follow-up questions like this are more than welcome! Please also include a link to this question to provide the background. –  Werner Jul 10 '12 at 23:22
add comment

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.