0

This is my LaTeX document containing some Java code:

\documentclass[12pt, oneside,titlepage]{book} % add a4paper
\usepackage[italian]{babel}
\usepackage{geometry}    
\usepackage{color}

\definecolor{pblue}{rgb}{0.13,0.13,1}
\definecolor{pgreen}{rgb}{0,0.5,0}
\definecolor{pred}{rgb}{0.9,0,0}
\definecolor{pgrey}{rgb}{0.46,0.45,0.48}
\usepackage{listings}
\lstset{language=Java,
    showspaces=false,
    showtabs=false,
    breaklines=true,
    showstringspaces=false,
    breakatwhitespace=true,
    commentstyle=\color{pgreen},
    keywordstyle=\color{pblue},
    stringstyle=\color{pred},
    basicstyle=\small\ttfamily,
    moredelim=[il][\textcolor{pgrey}]{$$},
    moredelim=[is][\textcolor{pgrey}]{\%\%}{\%\%},
    tabsize=3  % 1 tab = X spazi
}

\begin{document}
\begin{lstlisting}[frame = single]
public void updateState() {
    ItemUpdaterFactory factory = ItemUpdaterFactory.getInstance();
    String strategy = ConfigFileReader.getProperty("update_strategy");
    for (Item item : items) {
        ItemUpdater updater = factory.getUpdater(item,strategy);
        updater.updateQuality(item);
        updater.updateSellIn(item);
    }
}
\end{lstlisting}
\end{document}

whose result is:

enter image description here

As you can see, because of the length of the statements, they get "cut" (e.g. String strategy = ...).

How can I avoid this and show my code properly?

9
  • 1
    Are you looking for a way to disable line breaks? If yes: breaklines=false Jan 16 at 17:54
  • @samcarter_is_at_topanswers.xyz I am looking for a way to avoid my statements to be clipped: I wish they got show in their whole "width". For instance, enlarge the frame width
    – tail
    Jan 16 at 17:55
  • 1
    ... but they aren't clipped, they are wrapped into the next line Jan 16 at 17:56
  • @samcarter_is_at_topanswers.xyz I know. I meant I want to avoid that wrapping
    – tail
    Jan 16 at 17:56
  • 1
    Then you need to make the text width of your document wider. You can reduce the size of the margins with the geometry package. Jan 16 at 17:57

0

You must log in to answer this question.

Browse other questions tagged .