Skip to content

Commit

Permalink
Add CASE to algorithmic.
Browse files Browse the repository at this point in the history
  • Loading branch information
weijianwen committed Jan 8, 2016
1 parent 8f4d169 commit 0a42901
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 14 deletions.
21 changes: 21 additions & 0 deletions sjtuthesis.cls
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,27 @@
\newtheorem{bprop}[thm]{\sjtu@label@prop~}
\newtheorem{bcor}[thm]{\sjtu@label@cor~}
\renewcommand{\proofname}{\bf\sjtu@label@proof}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following definitions are to extend the LaTeX algorithmic
% package with SWITCH statements and one-line structures.
% The extension is by
% Prof. Farn Wang
% Dept. of Electrical Engineering,
% National Taiwan University.
%
\newcommand{\SWITCH}[1]{\STATE \textbf{switch} (#1)}
\newcommand{\ENDSWITCH}{\STATE \textbf{end switch}}
\newcommand{\CASE}[1]{\STATE \textbf{case} #1\textbf{:} \begin{ALC@g}}
\newcommand{\ENDCASE}{\end{ALC@g}}
\newcommand{\CASELINE}[1]{\STATE \textbf{case} #1\textbf{:} }
\newcommand{\DEFAULT}{\STATE \textbf{default:} \begin{ALC@g}}
\newcommand{\ENDDEFAULT}{\end{ALC@g}}
\newcommand{\DEFAULTLINE}[1]{\STATE \textbf{default:} }
%
% End of the LaTeX algorithmic package extension.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%==========
% Segment 4. Draw the sjtuthesis
%==========
Expand Down
52 changes: 38 additions & 14 deletions tex/chapter02.tex
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ \section{向文档中插入图像}
\subsection{支持的图片格式}
\label{sec:imageformat}

\XeTeX 可以很方便地插入PDF、EPS、PNG、JPG格式的图片。
\XeTeX 可以很方便地插入PDF、PNG、JPG格式的图片。

插入PNG/JPG的例子如\ref{fig:SRR}所示。
这两个水平并列放置的图共享一个“图标题”(table caption),没有各自的小标题。
Expand All @@ -118,19 +118,19 @@ \subsection{支持的图片格式}
\bicaption[fig:SRR]{这里将出现在插图索引中}{中文题图}{Fig}{English caption}
\end{figure}

这里还有插入eps图像和pdf图像的例子,如图\ref{fig:epspdf:a}和图\ref{fig:epspdf:b}。这里将EPS和PDF图片作为子图插入,每个子图有自己的小标题。并列子图的功能是使用subfigure宏包提供的。

\begin{figure}
\centering
\subfigure[EPS Figure]{
\label{fig:epspdf:a} %% label for first subfigure
\includegraphics[width=0.3\textwidth]{chap2/sjtulogo.eps}}
\hspace{1in}
\subfigure[PDF Figure]{
\label{fig:epspdf:b} %% label for second subfigure
\includegraphics[width=0.3\textwidth]{chap2/sjtulogo.pdf}}
\bicaption[fig:pdfeps]{插入eps图像和pdf图像}{插入eps和pdf的例子}{Fig}{An EPS and PDF demo}
\end{figure}
% 这里还有插入eps图像和pdf图像的例子,如图\ref{fig:epspdf:a}和图\ref{fig:epspdf:b}。这里将EPS和PDF图片作为子图插入,每个子图有自己的小标题。并列子图的功能是使用subfigure宏包提供的。
%
% \begin{figure}
% \centering
% \subfigure[EPS Figure]{
% \label{fig:epspdf:a} %% label for first subfigure
% \includegraphics[width=0.3\textwidth]{chap2/sjtulogo.eps}}
% \hspace{1in}
% \subfigure[PDF Figure]{
% \label{fig:epspdf:b} %% label for second subfigure
% \includegraphics[width=0.3\textwidth]{chap2/sjtulogo.pdf}}
% \bicaption[fig:pdfeps]{插入eps图像和pdf图像}{插入eps和pdf的例子}{Fig}{An EPS and PDF demo}
% \end{figure}

更多关于 \LaTeX 插图的例子可以参考\href{http://www.cs.duke.edu/junhu/Graphics3.pdf}{《\LaTeX 插图指南》}。

Expand Down Expand Up @@ -313,3 +313,27 @@ \section{用algorithm和algorithmic宏包插入算法描述}
\end{algorithmic}
\end{algorithm}

王凡教授\footnote{\url{http://cc.ee.ntu.edu.tw/~farn/}}对algorithmic做了扩展,支持\verb+STATE+、\verb+SWITCH+和\verb+CASE+等语句。

\begin{algorithm}
\caption{fibonacci}
\label{algo: Fibonacci Sequence}
\begin{algorithmic}
\REQUIRE $num$

\STATE $res \leftarrow 0$
\SWITCH {$num$}
\CASE {$0$}
\STATE $res \leftarrow 1$
\ENDCASE
\CASE {$1$}
\STATE $res \leftarrow 1$
\ENDCASE
\DEFAULT
\STATE $res \leftarrow fibonacci(num-1) + fibonacci(num-2)$
\ENDDEFAULT
\ENDSWITCH

\RETURN $res$
\end{algorithmic}
\end{algorithm}

0 comments on commit 0a42901

Please sign in to comment.