Building on this example:
\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}
How can I define a new column type in which the entire content of every cell is surrounded by a lstlisting environment without typing it?
\begin{LARGE}some text \end{LARGE}? – Orion Jul 11 '16 at 11:43&,\\and\end{longtable}so detecting the end of the cell is tricky. It's not impossible but it's sufficiently fragile and specific to (in this case) listings-inside-longtable, that I wouldn't suggest doing it. – David Carlisle Jul 11 '16 at 12:09\begin{LARGE}...\end{LARGE}– Jul 11 '16 at 12:12