使用Uestc硕士模板无法使用listings包

2021-02-07 14:04发布

## 编译环境 操作系统 * [x] Windows 10 * [ ] macOS * [ ] Linux `若需勾选,请把[ ]改成[x]` Tex发行版 * [x] TexLive `2020`...

## 编译环境 操作系统 * [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打开一下该模板,编译一下试试呢
1条回答
Banach spaces
2021-02-07 15:18
缺少\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)

一周热门 更多>