定义新的列类型,其中内容被环境包围

定义新的列类型,其中内容被环境包围

在此基础上例子

\documentclass{article}
\RequirePackage{longtable,nameref}

\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{listings}
\lstset{
    frame=single,
    breaklines=true,
    postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\color{red}\hookrightarrow\space}}
}

\lstdefinelanguage{numpy}{
    keywords = {
        and,del,from,not,while,
        as,elif,global,or,with,
        assert,else,if,pass,yield,
        break,except,import,print,
        class,exec,in, raise,continue,
        finally,is, return,def,for,
        lambda,try
    },
    morekeywords = {numpy,fft,mean}
}

\begin{document}

    \begin{longtable}[t]{l l} 
        \caption{Table caption.}
        \label{tab:table1}

        \\

        a &

        \begin{lstlisting}[language=numpy]
        def autocorrelate(A):
        avgsq = A.mean()**2
        sigma = (A**2).mean() - avgsq
        corr = numpy.real(numpy.fft.ifft( numpy.fft.fft(A).conj() * numpy.fft.fft(A) )) / A.shape[0]
        corr = (corr - avgsq)/sigma
        return corr
        \end{lstlisting}
        \\

        b &

        def autocorrelate(A):
        avgsq = A.mean()**2
        sigma = (A**2).mean() - avgsq
        corr = numpy.real(numpy.fft.ifft( numpy.fft.fft(A).conj() * numpy.fft.fft(A) )) / A.shape[0]
        corr = (corr - avgsq)/sigma
        return corr

        \\
    \end{longtable}         

\end{document}

我如何定义一种新的列类型,其中每个单元格的全部内容都被环境包围,而lstlisting无需输入它?

相关内容