如何在一个列表中创建两个 \lstinputlisting

如何在一个列表中创建两个 \lstinputlisting

在以下文档中:

\usepackage{longtable}
\usepackage{amsmath}
\usepackage{url}
\usepackage{booktabs} % For formal tables
\usepackage{listings}
\usepackage{color}
\usepackage{commath}
\usepackage{float}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{frame=tb,
    language=Java,
    aboveskip=3mm,
    belowskip=3mm,
    showstringspaces=false,
    columns=flexible,
    basicstyle={\fontsize{7}{8}\ttfamily},
    numbers=left,
    stepnumber=1,
    numberstyle=\tiny\color{gray},
    keywordstyle=\color{blue},
    commentstyle=\color{dkgreen},
    stringstyle=\color{mauve},
    breaklines=true,
    breakatwhitespace=true,
    tabsize=3
}

\begin{document}
    \lstinputlisting[language=Java,caption={A simple Java method}, label={lst:defectExample}, captionpos=b]{./CodeSnippets/DefectExample.java}

    \lstinputlisting[language=Java,caption={Testing the method}, label={lst:defectExample}, captionpos=b]{./CodeSnippets/DefectExampleTest.java}
\end{document}

如何将两个lstinputlisting列表合并为一个列表,并且每个列表都有自己的标题?我尝试添加它们,\begin{listing} \end{listing}但出现错误Environment listing undefined. \begin{listing}

有人能帮我修复这个问题吗?

相关内容