I am trying to create pattern to list my Java source code. It looks pretty nice, but there are some problems when I try to list XML code. Here is how it's done:
Code: Select all
\documentclass[11pt,a4paper]{article}
\usepackage{listings}
\usepackage{color}
\usepackage{xcolor}
\usepackage{caption}
% ustawienia odnosnie listowania kodu zrodlowego ******
\lstset{language=Java,captionpos=t,tabsize=3,frame=no,keywordstyle=\color{blue},
commentstyle=\color{gray},stringstyle=\color{red},numbers=left,numberstyle=\tiny,
numbersep=5pt,breaklines=true,showstringspaces=false,basicstyle=\footnotesize,emph={label}}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox{darkgray}{\parbox[c][0.3cm]{\textwidth}{#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
% ****************************************************
\begin{document}
\section{IoC - dependency injection}
\begin{lstlisting}[language=XML,caption=applicationContext.xml]
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="weatherService" class="pl.edu.uj.spring.WeatherServiceImpl">
<property name="weatherDao">
<ref local="weatherDao"/>
</property>
</bean>
<bean id="weatherDao" class="pl.edu.uj.spring.StaticDataWeatherDaoImpl">
</bean>
</beans>
\end{lstlisting}
\begin{lstlisting}[caption=Application.java]
package pl.edu.uj.spring;
import java.util.GregorianCalendar;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("pl/edu/uj/spring/applicationContext.xml");
WeatherService ws = (WeatherService) ctx.getBean("weatherService");
Double high = ws.getHistoricalHigh(new GregorianCalendar(2010,07,05).getTime());
System.out.println(high);
}
}
\end{lstlisting}
\end{document}
I am LaTeX newbie so your patience is very appreciated

Thanks,
Piotr
Edit by localghost: No external links! Attachments go onto the forum server (see Board Rules).