# How to change font size for specific lstlisting

I have a java lstlisting and it is too big and does not mach a single page.

Is there any way to specify font for specific listing, not all listings in document?

-

You can set the option directly with the lstlisting environment option basicstyle

\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[
basicstyle=\tiny, %or \small or \footnotesize etc.
]
int isJava = 1;
\end{lstlisting}
\end{document}


-

The best way to do this is by using the lstdefinestyle functionality which is built into the listings package. Encapsulate your style as follows (I've used a crummy MATLAB style definition as an example):

\lstdefinestyle{myCustomMatlabStyle}{
language=Matlab,
numbers=left,
stepnumber=1,
numbersep=10pt,
tabsize=4,
showspaces=false,
showstringspaces=false
}


Then, use it like so:

% A "large" listing
\lstset{basicstyle=\large,style=myCustomMatlabStyle}

\begin{lstlisting}
...
\end{lstlisting}

% A "tiny" listing
\lstset{basicstyle=\tiny,style=myCustomMatlabStyle}

\begin{lstlisting}
...
\end{lstlisting}


The results of the two different lstlisting's will be different sizes, as set by your basicstyle command.

-
Be careful with \lstset, though; its effects are global. – Jubobs May 25 '14 at 8:42