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 have been writing a large latex document, but I got some trouble with figures. Usually when I want to add an image or a listing to my list of figures, I just place it within \begin{figure} and \end{figure}. But the figure-environment is floating all the time and does not care about indentation. So, for some listings and images I use the minipage-environment to prevent floating. But the problem is, I don't know how to add those minipages to the list of figures.

A non-floating listing example:

\lstinputlisting[language=XML, 
label=lst:xsl_script, 
numbers=left, 
captionpos=b, 
caption=some caption]{documents/analyze.xml}

where analyze.xml is pretty short (5 lines) so I want it to be placed right here.

I know, I could surround it with \begin{figure}[!htbp] ... \end{figure} and it would be placed at the position I want, but nevertheless the indentation would be messed up.

So my question is, how to add listings and images to the list of figures without surrouding them with a figure-environment?

Thanks.

share|improve this question

migrated from stackoverflow.com Sep 16 '13 at 0:08

This question came from our site for professional and enthusiast programmers.

1  
you can use the capt-of package and put \captionof{figure}{my caption} in the minipage (it is \caption that writes to the list of figures), but please always post complete documents that show the problem, figure and minipage have the same behaviour with respect to indentation, so your description doesn't seem quite right and some other factor must be causing your problem. –  David Carlisle Sep 16 '13 at 0:23
    
@DavidCarlisle you are completely right. I just have to use \captionof{figure}{my caption} together with \captionsetup{type=figure} within the minipage and it will be added to the list of figures as I wanted it. Thanks. –  FrecherxDachs Sep 16 '13 at 18:37

1 Answer 1

up vote 2 down vote accepted

Solution:

\begin{minipage}{\linewidth}
  \captionsetup{type=figure}
  \lstinputlisting[language=XML, numbers=left]{documents/analyze.xml}
  \caption{my caption}
  \label{fig:xsl_script}
\end{minipage}

Thanks to David and Axel.

share|improve this answer
1  
Since you are using \captionsetup{type=figure} the regular caption command could be used, i.e. \caption{my caption} (instead of \captionsetup{figure}{my caption}) –  Axel Sommerfeldt Sep 17 '13 at 7:05
    
Thank you, without \captionsetup{type=figure} the tex compiler threw an error, so it seems, I need it here in any way. I changed the code as you suggested. –  FrecherxDachs Sep 17 '13 at 7:33

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.