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:

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?


  • 2
    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. 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. Sep 16 '13 at 18:37


  \lstinputlisting[language=XML, numbers=left]{documents/analyze.xml}
  \caption{my caption}

Thanks to David and Axel.

  • 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})
    – user2574
    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. Sep 17 '13 at 7:33

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.