## 编译环境 操作系统 * [x] Windows 10 * [ ] macOS * [ ] Linux `若需勾选,请把[ ]改成[x]` Tex发行版 * [x] TexLive `2020` * [ ] MikTeX `版本号` * [ ] CTeX `若需勾选,请把[ ]改成[x]` ## 我的问题 我在使用UESTC的latex模板的时候无法使用listings包,为了插入代码才选择用这个包的。 现在按照官方listings文档,无法把代码插进去,提示错误 Environment lstlisting undefined. 代码如下: ``` \documentclass{article} \usepackage{listings} \begin{document} \begin{lstlisting} public static void main(String[] args) { System.out.println("Hello World"); } \end{lstlisting} \end{document} ``` 使用的模板见附件,使用xelatex编译main_file.tex即可。希望可以使用TexLive2020打开一下该模板,编译一下试试呢
2019ThesisUESTC- PROFESSIONAL MASTER.zip
476KB

1 回答1

0
缺少\end{document} ```cpp \documentclass{article} \usepackage{listings} \begin{document} \begin{lstlisting} public static void main(String[] args) { System.out.println("Hello World"); } \end{lstlisting} \end{document} ``` ![](https://wenda.latexstudio.net/data/attach/210207/Lz8vuWYZ.jpg) 没有设置lst, ```cpp \documentclass{article} \usepackage{listing} \begin{document} \begin{listing} public static void main(String[] args) { System.out.println("Hello World"); } \end{listing} \end{document} ``` 设置lst,例子如下: ```cpp \documentclass{article} \usepackage{tcolorbox} \tcbuselibrary{listings} \lstdefinestyle{mystyle}{ basicstyle=% \ttfamily \lst@ifdisplaystyle\small\fi } \lstset{basicstyle=\ttfamily,style=mystyle} \definecolor{structurecolor}{RGB}{0,120,2}% \definecolor{winered}{rgb}{0.5,0,0} \definecolor{lightgrey}{rgb}{0.9,0.9,0.9} \definecolor{frenchplum}{RGB}{190,20,83} \lstset{language=[LaTeX]TeX, texcsstyle=*\color{magenta}, numbers=left, numberstyle=\tiny\color{blue}, stepnumber=1, numbersep=5pt, breaklines=true, basicstyle=\scriptsize\ttfamily\color{blue!80!black}, keywordstyle=\color{magenta}, commentstyle=\color{gray}, morestring=[s][\bfseries\color{blue!40}]{\[}{\]}, morestring=[s][\bfseries\color{cyan}]{\{}{\}}, %morestring=[s][\bfseries\color{violet}]{(}{)}, emph={main,none,fontenc,fontspec,xeCJK,FiraMono,xunicode,newtxmath,figure,fig,image,img,table,itemize,enumerate,newtxtext,newtxtt,ctex,microtype,description,times,newtx,booktabs,tabular,PDFLaTeX,XeLaTeX,type1cm,BibTeX,device,color,mode,lang,amsthm,tcolorbox,titlestyle,cite,marginnote,ctex,listings}, emphstyle={\color{yellow!20!red}}, morekeywords={main,pic,DeclareSymbolFont,SetSymbolFont,toprule,midruletikzstyle,bottomrule,institute,version,includegraphics,setmainfont,setsansfont,setmonofont ,setCJKmainfont,setCJKsansfont,setCJKmonofont,RequirePackage,figref,tabref,email,maketitle,keywords,definecolor,extrainfo,logo,cover,subtitle,appendix,chapter,hypersetup,mainmatter,tableofcontents,elegantpar,numbers,authoryear,heiti,kaishu,lstset,pagecolor,zhnumber,marginpar,part,equote}, frame=shadowbox, rulesepcolor=\color{blue!15!white}, tabsize=2, rulecolor=\color{blue!30}, framerule=0.5pt, columns=flexible, backgroundcolor=\color{gray!40!white} } \begin{document} \begin{lstlisting} frame=shadowbox, rulesepcolor=\color{blue!15!white}, tabsize=2, rulecolor=\color{blue!30}, framerule=0.5pt, columns=flexible, %backgroundcolor=\color{lightgrey} public static void main(String[] args) { System.out.println("Hello World"); } \end{lstlisting} \end{document} ``` 效果如下: ![](https://wenda.latexstudio.net/data/attach/210207/mBcHMdcK.jpg)
  • 好的,谢谢,按照你的,问题解决了! – Coder 2021-02-07 18:36 回复
  • 回复 Coder :环境lstlisting中lst需要自己设置;上面我的回答里面我修改了一下。 – Banach spaces 2021-02-07 15:44 回复
  • 不好意思,问题里面少粘贴了,其实是有的。但还是那个问题 – Coder 2021-02-07 15:22 回复

你的回答

请登录后回答

你的回答将会帮助更多人,请务必认真回答问题。