首页 > 技术文章 > Latex写算法伪代码【线上编辑篇】

wayne-tao 2022-03-29 11:33 原文

线上编辑网站:over leaf 

 https://cn.overleaf.com/project

 

 下方可以选择调整语言

示范代码:

%! Tex program = xelatex
\documentclass[a4paper,12pt]{article}
\usepackage{CJK}
\usepackage{algorithm} 
\usepackage{algpseudocode} 
\begin{document} 
\begin{CJK}{UTF8}{gbsn} 
\begin{algorithm} 
    \floatname{algorithm}{算法}
    \setcounter{algorithm}{3}
    \caption{算法名字} 
    \hspace*{0.02in} {\bf Input:} 输入\\ 
    \hspace*{0.02in} {\bf Output:} 输出 
    \begin{algorithmic}[1]
    \iffalse
    \fi
        \State //普通段落
        \While {seed count} 
        \State while内容 
        \EndWhile 
        \Function {score函数名}{$seed, maxScore$}
            \State 函数内容
        \EndFunction
        \For{i $in$ MAX}
            \State 循环内容
        \EndFor
        \If {if判断条件}
            \State if内容
        \Else
            \State else内容
        \EndIf
    \end{algorithmic} 
\end{algorithm}
\end{CJK} 
\end{document}

结果展示:

 

 

有个不好处就是只能导出PDF,要是能导出三线表的word版本就好了23333333

 

推荐阅读