![定义新的列类型,其中内容被环境包围](https://linux22.com/image/337355/%E5%AE%9A%E4%B9%89%E6%96%B0%E7%9A%84%E5%88%97%E7%B1%BB%E5%9E%8B%EF%BC%8C%E5%85%B6%E4%B8%AD%E5%86%85%E5%AE%B9%E8%A2%AB%E7%8E%AF%E5%A2%83%E5%8C%85%E5%9B%B4.png)
在此基础上例子:
\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
无需输入它?