Latex 学习笔记--table 和 algorithm的写法

稍微整理下latex 写table和algorithm的方法,大多是对网上搜索到的内容的整理

参考内容 http://blog.sina.com.cn/s/blog_5e16f1770102ezhv.html


最简单的table的写法:

代码

\begin{table} 
\begin{center} 
\caption{your table caption} 
\begin{tabular}{|c|c|} 
\hline 
Notations & Descriptions \\ 
\hline 
T,Q,C & time series  \\ 
\hline 
your content... & your content... \\ 
\hline 
your content... & your content... \\ 
\hline 
\end{tabular} 
\end{center} 
\end{table}

效果


其中|c|c|表示有两列,定义好有几列以后接下来是写表格中每一行的内容

\hline表示在下面画一条横线。


latex 写algorithm的方法:

algorithm排版可能需要的套件

\documentclass[journal]{IEEEtran}
\usepackage{algorithm}
%\usepackage{algorithmic}
\usepackage{algpseudocode}
\usepackage{amsmath}
\usepackage{graphics}
\usepackage{epsfig}

其中algorithmic在compile时会出现错误

! LaTex Error: Command \algorithm already defined.

Or name \end... illegal, see p.192 of the manual

原因不是很清楚,所以只好先mark掉.

在算法中显示Input  和Output 关键字:

\renewcommand{\algorithmicrequire}{\textbf{Input:}} % Use Input in the format of Algorithm
\renewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm

样式1:

\begin{algorithm}[htb] 
\caption{ Framework of ensemble learning for our system.} 
\label{alg:Framwork} 
\begin{algorithmic}[1] 
\Require 
The set of positive samples for current batch, $P_n$; 
The set of unlabelled samples for current batch, $U_n$; 
Ensemble of classifiers on former batches, $E_{n-1}$; 
\Ensure 
Ensemble of classifiers on the current batch, $E_n$; 
\State Extracting the set of reliable negative and/or positive samples $T_n$ from $U_n$ with help of $P_n$; 
\label{code:fram:extract} 
\State Training ensemble of classifiers $E$ on $T_n \cup P_n$, with help of data in former batches; 
\label{code:fram:trainbase} 
\State $E_n=E_{n-1}cup E$; 
\label{code:fram:add} 
\State Classifying samples in $U_n-T_n$ by $E_n$; 
\label{code:fram:classify} 
\State Deleting some weak classifiers in $E_n$ so as to keep the capacity of $E_n$; 
\label{code:fram:select} \\ 
\Return $E_n$; 
\end{algorithmic} 
\end{algorithm}

排版效果:


样式2:

\begin{algorithm}[h] 
\caption{An example for format For \& While Loop in Algorithm} 
\begin{algorithmic}[1] 
\For{each $i\in [1,9]$} 
\State initialize a tree $T_{i}$ with only a leaf (the root); 
\State $T=T\cup T_{i};$ 
\EndFor 
\ForAll {$c$ such that $c\in RecentMBatch(E_{n-1})$} 
\label{code:TrainBase:getc} 
\State $T=T\cup PosSample(c)$; 
\label{code:TrainBase:pos} 
\EndFor; 
\For{$i=1$; $i<n$; $i++$ } 
\State $//$ Your source here; 
\EndFor 
\For{$i=1$ to $n$} 
\State $//$ Your source here; 
\EndFor 
\State $//$ Reusing recent base classifiers. 
\label{code:recentStart} 
\While {$(|E_n| \leq L_1 )and( D \neq \phi)$} 
\State Selecting the most recent classifier $c_i$ from $D$; 
\State $D=D-c_i$; 
\State $E_n=E_n+c_i$; 
\EndWhile 
\label{code:recentEnd} 
\end{algorithmic} 
\end{algorithm}


排版效果:



样式3:

\begin{algorithm}[h] 
\caption{Conjugate Gradient Algorithm with Dynamic Step-Size Control} 
\label{alg::conjugateGradient} 
\begin{algorithmic}[1] 
\Require 
$f(x)$: objective funtion; 
$x_0$: initial solution; 
$s$: step size; 
\Ensure 
optimal $x^{*}$ 
\State initial $g_0=0$ and $d_0=0$; 
\Repeat 
\State compute gradient directions $g_k=\bigtriangledown f(x_k)$; 
\State compute Polak-Ribiere parameter $\beta_k=\frac{g_k^{T}(g_k-g_{k-1})}{\parallel g_{k-1} \parallel^{2}}$; 
\State compute the conjugate directions $d_k=-g_k+\beta_k d_{k-1}$; 
\State compute the step size $\alpha_k=s/\parallel d_k \parallel_{2}$; 
\Until{($f(x_k)>f(x_{k-1})$)} 
\end{algorithmic} 
\end{algorithm}

排版效果:



先前使用的套件为algorithm或algorithmic,接下来介绍另一个写algorithm的套件algorithm2e

首先使用\usepackage 指令

\usepackage[linesnumbered,boxed]{algorithm2e}

样式4:

\begin{algorithm} 
\caption{identifyRowContext} 
\KwIn{$r_i$, $Backgrd(T_i)$=${T_1,T_2,\ldots ,T_n}$ and similarity threshold $\theta_r$} 
\KwOut{$con(r_i)$} 
$con(r_i)= \Phi$\; 
\For{$j=1;j \le n;j \ne i$} 

float $maxSim=0$\; 
$r^{maxSim}=null$\; 
\While{not end of $T_j$} 

compute Jaro($r_i,r_m$)($r_m\in T_j$)\; 
\If{$(Jaro(r_i,r_m) \ge \theta_r)\wedge (Jaro(r_i,r_m)\ge r^{maxSim})$} 

replace $r^{maxSim}$ with $r_m$\; 


$con(r_i)=con(r_i)\cup {r^{maxSim}}$\; 

return $con(r_i)$\; 
\end{algorithm}


排版效果:


如果想要去掉算法中的竖线:

在\begin{algorithm}之后加入\SetAlgoNoLine


  • 13
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值