Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
3  
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

1 Answer 1

up vote 3 down vote accepted

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}

enter image description here

share|improve this answer

Your Answer

 
discard

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.