Sfoglia il codice sorgente

adjust number style of code, set number of code in appendix & add better examples

VictorSheng 6 anni fa
parent
commit
22dd51d84e
5 ha cambiato i file con 44 aggiunte e 6 eliminazioni
  1. 10 1
      BUPTthesisbachelor.sty
  2. 4 0
      README.md
  3. 4 0
      code/recursion.py
  4. BIN
      main.pdf
  5. 26 5
      main.tex

+ 10 - 1
BUPTthesisbachelor.sty

@@ -277,7 +277,6 @@ pdfborder=001, linkcolor=black, citecolor=black, urlcolor=black]{hyperref}
 % Code 
 \usepackage{listings}
 \usepackage{xcolor}
-\renewcommand{\lstlistingname}{\kaishu{代码}}
 \lstset{
     basicstyle=\ttfamily\wuhao, %五号等宽字体
     extendedchars=true,
@@ -293,6 +292,7 @@ pdfborder=001, linkcolor=black, citecolor=black, urlcolor=black]{hyperref}
     basewidth={0.5em,0.35em},
     frame=single,              %单线边框,注释掉则无边框
     numbers=left,               %行号位于左侧
+    numberbychapter=true,
 %    xleftmargin=.5em,
 %    xrightmargin=.5em,
 %    aboveskip=1ex,
@@ -301,6 +301,15 @@ pdfborder=001, linkcolor=black, citecolor=black, urlcolor=black]{hyperref}
     escapeinside={\%*}{*)}
 }
 
+\renewcommand{\lstlistingname}{\kaishu{代码}}
+\makeatletter
+\AtBeginDocument{%
+  \renewcommand \thelstlisting
+       {\ifnum \c@chapter>\z@ \thechapter-\fi \@arabic\c@lstlisting}%
+}
+\makeatother
+
+
 % insert PDF
 \usepackage[final]{pdfpages}
 

+ 4 - 0
README.md

@@ -46,6 +46,7 @@ https://wj.qq.com/s/2116666/6661</font>
 - 新增区分奇偶页与否的配置选择(6/4)
 - 修正外文译文的页面样式问题(6/4)
 - 重整外文译文的图、表、公式编号(6/4)
+- 代码编号统一为图标编号样式,添加附录代码编号设置;增添代码文件引入示例(6/6)
 
 
 ## 系统需求
@@ -63,6 +64,9 @@ https://wj.qq.com/s/2116666/6661</font>
 
     (感谢<a href="https://github.com/MrAdonis">Li Jiarong</a>提供)
 
+- Ubuntu Linux
+    开源人员尚未在Ubuntu上进行过测试,欢迎尝试并顺利使用本模板的用户在Issue中提交自己的方案
+
 ## 如何使用
 
 ### 编辑以下文件

+ 4 - 0
code/recursion.py

@@ -0,0 +1,4 @@
+def numbers(x):
+    if x > 0:
+        print(x)
+        numbers(x-1)

BIN
main.pdf


+ 26 - 5
main.tex

@@ -1,7 +1,9 @@
+\def\thelstlisting{}
+
 %不需要区分奇偶页的请使用下面一行
-%\documentclass[a4paper,AutoFakeBold,oneside,12pt]{book}
+\documentclass[a4paper,AutoFakeBold,oneside,12pt]{book}
 %需要区分奇偶页的(即每一章第一页一定在奇数页上)请使用下面一行
-\documentclass[a4paper,AutoFakeBold,openright,12pt]{book}
+%\documentclass[a4paper,AutoFakeBold,openright,12pt]{book}
 \usepackage{BUPTthesisbachelor}
 \usepackage{setspace}
 
@@ -224,13 +226,21 @@
 \end{algorithm}
 
 \section{代码表示}
+
+%据悉以下语言被lstlisting支持:Awk, bash, Basi4, C#, C++, C, Delphi, erlang, Fortran, GCL, Haskell, HTML, Java, JVMIS, Lisp, Logo, Lua, make, Mathematica, Matlab, Objective C , Octave, Pascal, Perl, PHP, Prolog,  Python, R, Ruby, SAS, Scilab, sh, SHELXL, Simula, SQL, tcl, TeX, VBScript, Verilog, VHDL, XML, XSLT
+%遗憾的是,JavaScript不被支持,请上网搜索支持该语言的方法
+ 
 下面的代码\ref{plus}是用Python编写的加法函数。
 
 \begin{lstlisting}[language=Python, caption=加法, label=plus, tabsize=2]  
-def plus_func(a, b):
-	return a + b
+def plusFunc(a, b):
+	return a + b 
 \end{lstlisting}  
 
+下面的代码\ref{recursion}是用Python文件中引入的倒序打印$x$到$1$的函数。
+
+\lstinputlisting[language=Python, caption=倒序打印数字, label=recursion, tabsize=2]{code/recursion.py}
+
 \section{列表样式}
 
 以下是使用圆点作为项目符号的列表样式。
@@ -273,6 +283,12 @@ def plus_func(a, b):
 \renewcommand{\theequation}{~附-\arabic{equation}~}
 \setcounter{table}{0} 
 \renewcommand{\thetable}{~附-\arabic{table}~}
+\setcounter{lstlisting}{0} 
+\makeatletter
+  \renewcommand \thelstlisting
+       {附-\@arabic\c@lstlisting}
+\makeatother
+
 
 \chapter*{附\qquad{}录}
 \phantomsection\addcontentsline{toc}{chapter}{附\qquad{}录}
@@ -308,7 +324,12 @@ def plus_func(a, b):
         \hline
     \end{tabular}
 \end{bupttable}
-\buptfigure[width=0.2\textheight]{pictures/autoencoder}{自编码器结构}{autoencoder}
+\buptfigure[width=0.15\textheight]{pictures/autoencoder}{自编码器结构}{autoencoder}
+
+\begin{lstlisting}[language=Python, caption=减法, label=minus, tabsize=2]  
+def minusFunc(a, b):
+	return a - b 
+\end{lstlisting}  
 
 \begin{equation}
 \label{PCA_goal}