# How to customize the caption format for \lstinputlisting

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.


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

-
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 at 13:39

You can use the package caption for customization your output.

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

\captionsetup[lstlisting]{font={small,tt}}


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

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

\documentclass{report}
\usepackage{filecontents}
\begin{filecontents*}{sample.py}
int main(int argc, char ** argv)
{
printf("Hello!\n");
return 0;
}
\end{filecontents*}
\usepackage{listings}
\usepackage{framed}

\usepackage{caption}
\captionsetup[lstlisting]{font={small,tt}}
\begin{document}

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


-