美文网首页
LaTeX输入伪代码

LaTeX输入伪代码

作者: 自由即孤独 | 来源:发表于2021-10-10 10:01 被阅读0次

第一种方式:

\documentclass[a4paper]{ctexart}
\usepackage[noend]{algpseudocode}

\usepackage{algorithmicx,algorithm}
\begin{document}
hello
\begin{algorithm}[t]
\caption{algorithm caption} %算法的名字
\hspace*{0.02in} {\bf Input:} %算法的输入, \hspace*{0.02in}用来控制位置,同时利用 \\ 进行换行
input parameters A, B, C\\
\hspace*{0.02in} {\bf Output:} %算法的结果输出
output result
\begin{algorithmic}[1]
\State some description % \State 后写一般语句
\For{condition} % For 语句,需要和EndFor对应
    \State ...
    \If{condition} % If 语句,需要和EndIf对应
        \State ...
    \Else
        \State ...
    \EndIf
\EndFor
\While{condition} % While语句,需要和EndWhile对应
    \State ...
\EndWhile
    \State 
\Return result
\end{algorithmic}
\end{algorithm}
\end{document}

效果如下图:


1.jpg

第二种方式:

\documentclass[a4paper]{ctexart}
\usepackage[ruled]{algorithm2e}
\begin{document}
\begin{algorithm}[H]
\caption{algorithm caption}%算法名字
\LinesNumbered %要求显示行号
\KwIn{input parameters A, B, C}%输入参数
\KwOut{output result}%输出
some description\; %\;用于换行
\For{condition}{
    only if\;
    \If{condition}{
        1\;
    }
}
\While{not at end of this document}{
    if and else\;
    \eIf{condition}{
        1\;
    }{
        2\;
    }
}
\ForEach{condition}{
    \If{condition}{
        1\;
    }
}
\end{algorithm}
\end{document}

效果如下图:


2.jpg

第三种方式:

\documentclass[a4paper]{ctexart}
%\usepackage[ruled]{algorithm2e}
\usepackage[ruled,vlined]{algorithm2e}
\begin{document}
\begin{algorithm}[H]
\caption{algorithm caption}%算法名字
\LinesNumbered %要求显示行号
\KwIn{input parameters A, B, C}%输入参数
\KwOut{output result}%输出
some description\; %\;用于换行
\For{condition}{
    only if\;
    \If{condition}{
        1\;
    }
}
\While{not at end of this document}{
    if and else\;
    \eIf{condition}{
        1\;
    }{
        2\;
    }
}
\ForEach{condition}{
    \If{condition}{
        1\;
    }
}
\end{algorithm}
\end{document}

效果如下图:


3.jpg

如果使用beamer的话,就会出错。这是因为伪代码也是float元素。所以,需要使用float package。

\usepackage{float}

伪代码使用时,需要设置成H,而不是t。如下所示:
···
\begin{algorithm}[H]
···

相关文章

  • LaTeX输入伪代码

    第一种方式: 效果如下图: 第二种方式: 效果如下图: 第三种方式: 效果如下图: 如果使用beamer的话,就会...

  • 2018-04-03

    【LaTeX】Lyx/LaTeX笔记01---插入伪代码[latex]使用algorithm包来编写伪代码 - C...

  • Latex 写伪代码

    参考http://hustsxh.is-programmer.com/posts/38801.html[http:...

  • Latex写算法伪代码

    科研过程中利用Latex写文章是非常方便的一件事,下面是latex的一些写伪代码的代码。 1. Code One...

  • 【Latex】Pesudo code 排版

    CS论文中经常需要使用伪代码格式排版,用latex的algorithm和algorithmic 包进行专业风格的排...

  • 只用CSS定义checkbox的样式以及mac下设置input[

    1.1、纯css通过伪元素来定义input输入框激活样式 HTML代码: CSS伪元素实现代码: 注:1、加号为相...

  • Markdown基本语法及扩展

    中国科学技术大学 插入表格 相关代码: 输入公式 目前原生markdown语法不支持LaTeX代码公式,部分编辑器...

  • Markdown语法简介

    中国科学技术大学 插入表格 相关代码: 输入公式 目前原生markdown语法不支持LaTeX代码公式,部分编辑器...

  • 在word中插入latex伪代码

    使用word时,需要插入latex样式的伪代码,如下所示: 安装后打开word,如果有插件直接在插件里打开,没有的...

  • 自学LaTeX【2】:列LaTeX提纲

    自学LaTeX【2】:列LaTeX提纲 通过《十二因缘·茉香记》来看LaTeX的工作逻辑 代码命令如下所示: 代码...

网友评论

      本文标题:LaTeX输入伪代码

      本文链接:https://www.haomeiwen.com/subject/bmcholtx.html