# Fitting codes in a Latex Code block

    \usepackage{listings}
\begin{document}

\lstset{language=Java}

\begin{lstlisting}[frame=single]

String content = new PDFTextStripper().getText(doc);
doc.close();
return new Indexitem((long)file.getName().hashCode(), file.getName(), content);

\end{lstlisting}
\end{document}


Considering the above code, my question is how to fit the code into its block? Assuming we are using a double-column template.

,breakatwhitespace,gobble=10 is an alternative solution:

\documentclass{article}
\usepackage{listings}
\begin{document}

\lstset{language=Java}
%\begin{lstlisting}[frame=single,gobble=14,basicstyle=\scriptsize\ttfamily]
%\begin{lstlisting}[frame=single,breaklines,breakatwhitespace,gobble=10]
\begin{lstlisting}[frame=single,breaklines]


• but breaklines makes it ugly. I want each code to be represented in one individual line Moreover, the block looks ugly, the code has not equal spaces from all 4 corners. – lonesome Oct 2 '15 at 6:21
• makes no real sense. However, see edited answer with gobble=14,... – user2478 Oct 2 '15 at 6:26
• My question makes no real sense? But gobble=14,basicstyle=\scriptsize\ttfamily looks perfect. However it misses the some characters of each line. Can it be fixed? – lonesome Oct 2 '15 at 6:58
• Ok, I set globe=5 and things looks nice now. Thank you :) – lonesome Oct 2 '15 at 7:00