I am relatively new to LaTex and I am trying to add a single landscape table to my document. I have looked at this question and the given \afterpage example works great in my environment. However as soon as I try to insert a listing into my table, I am no longer able to compile the file. Here's the relevant code:
\documentclass[a4paper]{report}
\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{caption}
\usepackage{listings}
\usepackage{color}
\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=none,
language=Java,
aboveskip=3mm,
belowskip=0mm,
showstringspaces=false,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=none,
numberstyle=\tiny\color{gray},
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
breaklines=true,
breakatwhitespace=true,
tabsize=3
}
\begin{document}
\afterpage{
\clearpage
\thispagestyle{empty}
\begin{landscape}
\centering
\begin{tabular}{llll}
\hline
A & B & C &
\begin{lstlisting}
public int add(int a, int b){
int sum = a + b;
return sum;
}
\end{lstlisting}
\\
\hline
\end{tabular}
\captionof{table}{Table caption}
\end{landscape}
\clearpage
}
\end{document}
The error I get when running pdflatex is:
Runaway argument?
! Paragraph ended before \lst@next was complete.
<to be read again>
\par
l.103 \newpage
{\pagestyle{empty} \cleardoublepage}
?
Help would be greatly appreciated!
\documentclass{...}and ending with\end{document}. – Zarko Aug 03 '18 at 19:18