77

When I use a simple caption, tex puts it above the listing

\begin{lstlisting}[caption={My Caption}]
\end{lstlisting}

enter image description here

If I use \captionof, caption goes below the listing, but paragraph for next line doesn't work.

\begin{lstlisting}
Listing example
\end{lstlisting}
\captionof{lstlisting}{My caption}

Next line, Next line, Next line, Next line.

enter image description here

As you see, there is not a paragraph.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • 1
    listings has an option to change the position of the caption. Look in the documentation, sec 5.7 Captions. – Ulrike Fischer Apr 10 '16 at 12:20
  • Can you send me the link? – Rostislav Shtanko Apr 10 '16 at 12:24
  • Use texdoc listings, or search in the doc-folder of your texsystem. – Ulrike Fischer Apr 10 '16 at 12:30
  • 4
    I'm voting to close this question as off-topic because the topic could be solved by comments (and the O.P. was able to find it too) –  Apr 20 '16 at 21:52
  • 8
    @ChristianHupfer how is this off-topic? self answering questions is absolutely encouraged, and this is a valid question. Only problem is that the answer is edited in instead of being posted as answer... – TheFlow0360 Jul 05 '17 at 12:58
  • @TheFlow0360: The O.P. did not answer his question however. If you don't agree, cast a reopen vote –  Jul 05 '17 at 14:23

1 Answers1

108

[Answer from OP, originally edited into question]

I found a solution.

\begin{lstlisting}[caption={My Caption},captionpos=b]
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • 4
    @community it would help how solution is found (i.e. docuemntation references) – user1868607 Oct 22 '20 at 13:39
  • 2
    @Rodrigo Find the "listings" package in ctan.org (or search for "ctan lstlisting" in a search engine and find the first ctan link) then click on "Package documentation". This works for any LaTeX packages available in CTAN. – Breno Oct 26 '21 at 18:24