Here is the code
\lstdefinestyle{mystyle}{
frame=single,
}
\begin{figure*}[tbp!]
\begin{center}
\begin{tabular}{c}
\lstset{style=mystyle}
\lstinputlisting[]{code/method.cs}
\end{tabular}
\end{center}
\end{figure*}
what's defined in method.cs:
public string[] reverse(string[] array)
{
string[] newArray = new string[array.Length];
for (int index = 0; index < array.Length; index++)
newArray[array.Length-index-1] = array[index];
return newArray;
}
Error message:
Missing { inserted. \lstset{style=mystyle}
Missing } inserted. \lstset{style=mystyle}
Extra alignment tab has been changed to \cr. \lstset{style=mystyle}
You can't use `macro parameter character #' in restricted horizontal mode. \lstset{style=mystyle}
You can't use `macro parameter character #' in restricted horizontal mode. \lstset{style=mystyle}
You can't use `macro parameter character #' in restricted horizontal mode. \lstset{style=mystyle}
....
It seems removing the tabular environment works but I need that for centering purposes. What's the error?
Edit:
complete MWE:
\documentclass{article}
\usepackage{listings}
\lstdefinestyle{mystyle}{
% backgroundcolor=\color{backcolour},
frame=single,
}
\begin{document}
\begin{figure*}[tbp!]
\begin{center}
%\begin{tabular}{c}
\lstset{style=mystyle}
\lstinputlisting[]{method.cs}
%\end{tabular}
\end{center}
\end{figure*}
\end{document}
Again, I want the tabular environment. In any case, I'd like to know why this does not work. So please don't suggest to delete the tabular which I already knew would work.
centerenvironment, or instead a simple\centeringin the figure? – TobiBS Jun 06 '20 at 23:39\usepackage{listings}and using classarticledoesn't work at my side at all. – TobiBS Jun 06 '20 at 23:44\begin{tabular}{c}in order to horizontally center a listing. – leandriis Jun 07 '20 at 07:54figure*,centerandtabular, although it is a bit wider than the actual textwidth itself. (You can add\usepackage{showframe}to your preamble to get a visual representation of the width of the textwidth) – leandriis Jun 07 '20 at 07:55&character and that confuses the tabular environment. So much that even if you useframe=noneyou'd end up with errors... – Elad Den Jun 07 '20 at 14:53