5

I am getting Missing \endgroup inserted morekeywords={class,run}] on line 16 while compiling the tex. I am using TexStudio. How can I solve that problem?

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{listings}

\begin{document}

\clearpage

\begin{tabular}{|p{.4\textwidth}|p{.4\textwidth}|}

\begin{lstlisting}[basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,language={[AspectJ]Java},
numbersep=8pt,numbers=left,xleftmargin=0.5cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords={class,run}]

class PrintHelloThread ext Thread {
    void run(Dummy x) {
        out.println("Hello world")
    }
}
class X ext ProxifiedObject {
    PrintHelloThread thread
    void main(X x) {
        x.thread := new PrintHelloThread;
        x.thread.start(0);
        x.thread.join(0);
    }
}
\end{lstlisting}
&
\begin{lstlisting}[
basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,
language={[AspectJ]Java},
numbersep=8pt,
numbers=left,
xleftmargin=0.5cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords ={class,run}
]
class PrintHelloThread ext Thread {
    void run(Dummy x) {
        out.println("Hello world")
    }
}
class X ext ProxifiedObject {
    PrintHelloThread thread
    void main(X x) {
        x.thread := new PrintHelloThread;
        x.thread.start(0);
        x.thread.join(0);
    }
}
\\
\end{lstlisting}
\end{tabular}
\end{document}
0

2 Answers 2

5

I get same errors on TexLive 2013. Use \ltset{} in preamble for setting parameters of lstlisting environment:

    \documentclass{article}
    \usepackage[T1]{fontenc}
    \usepackage[latin9]{inputenc}
    \usepackage{listings,xcolor}
    \lstset{
    basicstyle={\scriptsize\ttfamily},
    identifierstyle={\color{black}},
    tabsize=2,language={[AspectJ]Java},
    numbersep=4pt,numbers=left,xleftmargin=0.5cm,frame=tlbr,framesep=2pt,framerule=0pt
}
    \lstset{emph={%  
       class, run%
        },emphstyle={\color{red}}%
    }%
    \begin{document}

    \clearpage

    \begin{tabular}{|p{.6\textwidth}|p{.6\textwidth}|}

    \begin{lstlisting}[]
    class PrintHelloThread ext Thread {
        void run(Dummy x) {
            out.println("Hello world")
        }
    }
    class X ext ProxifiedObject {
        PrintHelloThread thread
        void main(X x) {
            x.thread := new PrintHelloThread;
            x.thread.start(0);
            x.thread.join(0);
        }
    }
    \end{lstlisting}
    &
    \begin{lstlisting}[]
    class PrintHelloThread ext Thread {
        void run(Dummy x) {
            out.println("Hello world")
        }
    }
    class X ext ProxifiedObject {
        PrintHelloThread thread
        void main(X x) {
            x.thread := new PrintHelloThread;
            x.thread.start(0);
            x.thread.join(0);
        }
    }
    \\
    \end{lstlisting}
    \end{tabular}
    \end{document}
3
  • 1
    Thanks! do you know why some words are red color in the code snippet?
    – Hakan
    Mar 31, 2014 at 22:23
  • I deleted my comments (don't ask: I confused myself:-) Mar 31, 2014 at 22:42
  • @Hakan, yourwelcome. For red words, please watch at second \ltset settings.
    – user31034
    Mar 31, 2014 at 22:55
4

Sorry I mislead you on the previous question, you need an extra set of {} to hide listings from the table mechanism:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{listings}
\usepackage{color}
\begin{document}

\clearpage

\begin{tabular}{|p{.4\textwidth}|p{.4\textwidth}|}
{\begin{lstlisting}[basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,language={[AspectJ]Java},
numbersep=8pt,numbers=left,xleftmargin=0.5cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords={class,run}]

class PrintHelloThread ext Thread {
    void run(Dummy x) {
        out.println("Hello world")
    }
}
class X ext ProxifiedObject {
    PrintHelloThread thread
    void main(X x) {
        x.thread := new PrintHelloThread;
        x.thread.start(0);
        x.thread.join(0);
    }
}
\end{lstlisting}}
&
{\begin{lstlisting}[
basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,
language={[AspectJ]Java},
numbersep=8pt,
numbers=left,
xleftmargin=0.5cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords ={class,run}
]
class PrintHelloThread ext Thread {
    void run(Dummy x) {
        out.println("Hello world")
    }
}
class X ext ProxifiedObject {
    PrintHelloThread thread
    void main(X x) {
        x.thread := new PrintHelloThread;
        x.thread.start(0);
        x.thread.join(0);
    }
}
\end{lstlisting}}
\end{tabular}
\end{document}
1
  • that's okay :) thanks! but \hline does not work properly. Have you tried by inserting them after starting tabular and before ending tabular ?
    – Hakan
    Mar 31, 2014 at 22:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .