Skip to content

Commit

Permalink
Add an example of algorithm and algorithmic.
Browse files Browse the repository at this point in the history
  • Loading branch information
weijianwen committed Jan 8, 2016
1 parent 8f82cf2 commit c32eb61
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LATEXMK_OPT = -xelatex -gg -silent -f

all: $(THESIS).pdf

.PHONY : all clean validate
.PHONY : all clean validate view

$(THESIS).pdf : $(THESIS).tex $(TEX_DIR)/*.tex $(BIB_DIR)/*.bib sjtuthesis.cls sjtuthesis.cfg Makefile
-latexmk $(LATEXMK_OPT) $(THESIS)
Expand All @@ -17,6 +17,9 @@ validate :
xelatex -no-pdf -halt-on-error $(THESIS)
biber --debug $(THESIS)

view : $(THESIS).pdf
open $<

clean :
latexmk -C
-rm *.xdv *.bbl *.fls $(TEX_DIR)/*.xdv $(TEX_DIR)/*.aux $(TEX_DIR)/*.log $(TEX_DIR)/*.fls _tmp_.pdf *.xml
Expand Down
1 change: 1 addition & 0 deletions sjtuthesis.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
\def\sjtu@contentsname{目~~~~录}
\def\sjtu@listfigurename{插图索引}
\def\sjtu@listtablename{表格索引}
\def\sjtu@listalgorithmname{算法索引}

%%
%% labels in the title page
Expand Down
8 changes: 6 additions & 2 deletions sjtuthesis.cls
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
\RequirePackage{enumitem}
\RequirePackage{pdfpages}
\RequirePackage{calc}
\RequirePackage{algorithm, algorithmic}

%==========
% Segment 2. Define general-purpose LaTeX commands.
Expand Down Expand Up @@ -118,10 +119,12 @@
\linespread{1.3}

%% CTeX Settings
% 目录名、表格索引、插图索引
% 名称:目录、表格索引、插图索引、代码索引
\CTEXoptions[contentsname={\sjtu@contentsname}]
\CTEXoptions[listfigurename={\sjtu@listfigurename}]
\CTEXoptions[listtablename={\sjtu@listtablename}]
\renewcommand{\listalgorithmname}{\sjtu@listalgorithmname}
\floatname{algorithm}{\sjtu@label@algo}
% Title Settings at the chapter Level
\CTEXsetup[nameformat={\Large\bfseries}]{chapter}
\CTEXsetup[titleformat={\Large\bfseries}]{chapter}
Expand Down Expand Up @@ -160,10 +163,11 @@
\renewcommand{\bottomfraction}{0.65}
\renewcommand{\floatpagefraction}{0.60}

% 定公式、图、表编号为"3-1"的形式,即分隔符由.变为短杠
% 定公式、图、表、算法的编号为"3-1"的形式,即分隔符由.变为短杠
\renewcommand{\theequation}{\arabic{chapter}--\arabic{equation}}
\renewcommand{\thefigure}{\arabic{chapter}--\arabic{figure}}
\renewcommand{\thetable}{\arabic{chapter}--\arabic{table}}
\renewcommand{\thealgorithm}{\arabic{chapter}--\arabic{algorithm}}

% Title
\renewcommand{\lstlistingname}{\sjtu@value@listingname} %% 重命名Listings标题头
Expand Down
18 changes: 18 additions & 0 deletions tex/chapter02.tex
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,21 @@ \section{用listings插入源代码}
}
\end{lstlisting}

\section{用algorithm和algorithmic宏包插入算法描述}

如算法\ref{algo:sum_I_want}所示。

\begin{algorithm}
\caption{求和算法}
\label{algo:sum_I_want}
\begin{algorithmic}
\REQUIRE $n \geq 1$ %输入条件
\ENSURE $Sum = 1 + \cdots + n$ %输出
\STATE $Sum \leftarrow 0$ %\STATE 命名演示
\IF {$n < 1$} %条件语句
\PRINT {Input Error} %打印语句
\ENDIF
\RETURN Sum
\end{algorithmic}
\end{algorithm}

3 changes: 3 additions & 0 deletions thesis.tex
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
\addcontentsline{toc}{chapter}{\listfigurename} %将插图目录加入全文目录
\listoftables
\addcontentsline{toc}{chapter}{\listtablename} %将表格目录加入全文目录
% \listofalgorithms
% \addcontentsline{toc}{chapter}{代码索引} %将表格目录加入全文目录

\include{tex/symbol} % 主要符号、缩略词对照表

Expand All @@ -69,6 +71,7 @@
\renewcommand\theequation{\Alph{chapter}--\arabic{equation}}
\renewcommand\thefigure{\Alph{chapter}--\arabic{figure}}
\renewcommand\thetable{\Alph{chapter}--\arabic{table}}
\renewcommand\thealgorithm{\Alph{chapter}--\arabic{algorithm}}

%% 附录内容,本科学位论文可以用翻译的文献替代。
\include{tex/app_log}
Expand Down

0 comments on commit c32eb61

Please sign in to comment.