我Missing \endgroup inserted morekeywords={class,run}]
在编译 tex 时遇到第 16 行。我正在使用 TexStudio。我该如何解决这个问题?
\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}
答案1
我在 TexLive 2013 上遇到了同样的错误。\ltset{}
在序言中使用设置lstlisting
环境参数:
\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}
答案2
抱歉,我在上一个问题上误导了您,您需要一组额外的功能{}
来隐藏表格机制中的列表:
\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}