这是我的 LaTeX 文档,包含一些 Java 代码:
\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}
其结果是:
如您所见,由于语句的长度,它们被“截断”(例如 String strategies = ...)。
我该如何避免这种情况并正确显示我的代码?