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 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?

share|improve this question
up vote 33 down vote accepted

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

    basicstyle=\tiny, %or \small or \footnotesize etc.
int isJava = 1;

See also this answer

share|improve this answer

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):


Then, use it like so:

% A "large" listing


% A "tiny" listing


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

share|improve this answer
Be careful with \lstset, though; its effects are global. – Jubobs May 25 '14 at 8:42

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.