2

I have a new lstenvironment defined like this:

\lstnewenvironment{xml}
{\lstset{language=xml, basicstyle=\ttfamily, frame=single, captionpos=b}}
{}

Then I want to apply it in my code:

\begin{xml}[label=base,caption=A configuration XML file.]
<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <connecting>
        <url>something</url>
        <user>username</user>
        <password>password</password>
    </connecting>
</config>
\end{xml} 

In the output, I would expect caption printed at the bottom of the listing, however, it is not. Some suggestions? Do I need to include something more within \lstset?

MichalB
  • 263

1 Answers1

4

Your definition of the environment xml needs an optional argument.

\documentclass{article}

\usepackage{listings}
\lstnewenvironment{xml}[1][]
{\lstset{language=xml, basicstyle=\ttfamily, frame=single, captionpos=b,#1}}
{}
\begin{document}
\begin{xml}[label=base,caption=A configuration XML file.]
<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <connecting>
        <url>something</url>
        <user>username</user>
        <password>password</password>
    </connecting>
</config>
\end{xml}
\end{document}
Marco Daniel
  • 95,681
  • It works, thanks. However, could someone explain me the meaning of these optional arguments [1][] when defining \lstnewenvironment? I went through the documentation for listing, but still couldnt figure it out. – MichalB May 17 '13 at 14:56
  • @MichalB: See: http://tex.stackexchange.com/questions/1050/whats-the-difference-between-newcommand-and-newcommand/1057#1057 – Marco Daniel May 17 '13 at 15:01