I have captions on each of my listings. Each caption is prefaced with "Listing # [text]" where # is the number of the listing. Each caption is centered over my listing. How can I modify the options of these captions? Here is a visual:enter image description here

  1. I want to get truncate the caption to only contain [text]
  2. I want to move the position of the caption from the center towards the left-side
  1. If a listing has a title, it will be used instead of caption, but without "Listing #" line.

  2. Unfortunately centered titles are hardcoded into listings, so you need to change the code. Here is a solution: I've just took the package defined \@makecaption and deleted the secong \hfil and added \bfseries (note that \lst@maketitle uses \@makecaption and drops the first part. If you want to keept captions centered but titles left-aligned, you need to patch \lst@maketitle rather than \@maketitle).

Here us the result:

    \bfseries #1: #2\par

\begin{lstlisting}[title={Some listing}]

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.