TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know how to customize the caption format of lstlisting environment.

But how to do this if I used the \lstinputlisting command to import code?

My document contain below snippet.

\lstinputlisting[label=samplecode,caption=sample code,language=python]{sample.py}
share|improve this question
Where's the question? – Marco Daniel Jun 22 '12 at 18:02
@MarcoDaniel the question is how to customize the font style of caption for` lstinputlisting` command – pythonee Jun 23 '12 at 6:55
@MarcoDaniel for this case, i want to def the caption font inner frame as \small\tt – pythonee Jun 23 '12 at 6:59
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – Jubobs Mar 2 '14 at 13:39
up vote 4 down vote accepted

You can use the package caption for customization your output.

The modification can be done for lstlisting with the command captionsetup.


Here the font is set to small and typewriter family is used.

Please have a closer look at the manual. Here a complete example:

int main(int argc, char ** argv)
    return 0;


\lstinputlisting[label=samplecode,caption=sample code,language=python]{sample.py}

enter image description here

share|improve this answer

Your Answer


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.