3
    \usepackage{listings}           
    \begin{document}

\lstset{language=Java}        

\begin{lstlisting}[frame=single]  

             PDDocument doc = PDDocument.load(file);
             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.

1 Answer 1

0

,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]

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

\end{lstlisting}
\end{document}
4
  • 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
    Commented Oct 2, 2015 at 6:21
  • makes no real sense. However, see edited answer with gobble=14,...
    – user2478
    Commented Oct 2, 2015 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
    Commented Oct 2, 2015 at 6:58
  • Ok, I set globe=5 and things looks nice now. Thank you :)
    – lonesome
    Commented Oct 2, 2015 at 7:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .