I have a listing of my Java code currently the font is too big and the code runs off the page.
Here is what my listing looks like:
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityYou can change basicstyle
and linewidth
to achieve what you want. I, for example, use the following within my lstlistings-settings:
basicstyle=\footnotesize\ttfamily,
linewidth=\textwidth
Additionally, I import the courier package to get a nicer font for ttfamily
using \usepackage{courier}
EDIT: I also use Java code within LaTeX documents quite regularly. This is how my total setup looks like:
\lstset{
basicstyle=\footnotesize\ttfamily,
linewidth=\textwidth,
numbers=left,
numberstyle=\tiny\emptyaccsupp,
columns=flexible,
numbersep=5pt, % Abstand der Nummern zum Text
tabsize=3,
breaklines=true,
keywordstyle=\color{RoyalBlue}\textbf,
commentstyle=\color{ForestGreen},
frame=bottomline,
stringstyle=\color{WildStrawberry}\ttfamily,
showspaces=false,
showtabs=false,
xleftmargin=17pt,
framexleftmargin=17pt,
framexrightmargin=5pt,
framexbottommargin=4pt,
showstringspaces=false,
literate=%
{Ö}{{\"O}}1
{Ä}{{\"A}}1
{Ü}{{\"U}}1
{ß}{{\ss}}2
{ü}{{\"u}}1
{ä}{{\"a}}1
{ö}{{\"o}}1
}
\lstloadlanguages{
Java
}
\tiny
to \Huge
as a setting for basicstyle
. Just the usual LaTeX way of setting the font size
Dec 14, 2012 at 9:10
lstset
optionscolumns=fullflexible
andbasicstyle=\small
or evenbasicstyle=\scriptsize
.