文章目录

  • 1. 前言
  • 2. 正文
    • 2.1. 导言区
    • 2.2. 将长算法分割
    • 2.3. 调整算法文本字体大小
    • 2.4. 调整算法行距
  • 3. 小结

1. 前言

创作开始时间:2022年9月28日23:33:52

如题,对LaTeX写伪代码作一些探索。

2. 正文

2.1. 导言区

\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\usepackage{setspace}\errorcontextlines\maxdimen\makeatletter
\newcommand*{\algrule}[1][\algorithmicindent]{\makebox[#1][l]{\hspace*{.5em}\thealgruleextra\vrule height \thealgruleheight depth \thealgruledepth}}%
\newcommand*{\thealgruleextra}{}
\newcommand*{\thealgruleheight}{.75\baselineskip}
\newcommand*{\thealgruledepth}{.25\baselineskip}\newcount\ALG@printindent@tempcnta
\def\ALG@printindent{%\ifnum \theALG@nested>0% is there anything to print\ifx\ALG@text\ALG@x@notext% is this an end group without any text?% do nothing\else\unskip\addvspace{-1pt}% FUDGE to make the rules line up% draw a rule for each indent level\ALG@printindent@tempcnta=1\loop\algrule[\csname ALG@ind@\the\ALG@printindent@tempcnta\endcsname]%\advance \ALG@printindent@tempcnta 1\ifnum \ALG@printindent@tempcnta<\numexpr\theALG@nested+1\relax% can't do <=, so add one to RHS and use < instead\repeat\fi\fi
}%
\usepackage{etoolbox}
%\AtBeginEnvironment{algorithmic}{\footnotesize}
\patchcmd{\ALG@doentity}{\noindent\hskip\ALG@tlm}{\ALG@printindent}{}{\errmessage{failed to patch}}
\makeatother\newbox\statebox
\newcommand{\myState}[1]{%\setbox\statebox=\vbox{#1}%\edef\thealgruleheight{\dimexpr \the\ht\statebox+1pt\relax}%\edef\thealgruledepth{\dimexpr \the\dp\statebox+1pt\relax}%\ifdim\thealgruleheight<.75\baselineskip\def\thealgruleheight{\dimexpr .75\baselineskip+1pt\relax}%\fi\ifdim\thealgruledepth<.25\baselineskip\def\thealgruledepth{\dimexpr .25\baselineskip+1pt\relax}%\fi\State #1%\def\thealgruleheight{\dimexpr .75\baselineskip+1pt\relax}%\def\thealgruledepth{\dimexpr .25\baselineskip+1pt\relax}%
}

2.2. 将长算法分割

直接在分割点粘贴如下代码即可:

\algstore{bkbreak}
\end{algorithmic}
\end{algorithm}\begin{algorithm}
\begin{algorithmic}[1]
\algrestore{bkbreak}

2.3. 调整算法文本字体大小

在导言区加入:

\usepackage{etoolbox}
\AtBeginEnvironment{algorithmic}{\footnotesize}

参考:

  • Smaller font size of the algorithm description? https://tex.stackexchange.com/questions/12110/smaller-font-size-of-the-algorithm-description

2.4. 调整算法行距

参考这个即可

  • Reduce vertical spacing in the algorithm environment https://tex.stackexchange.com/questions/16059/reduce-vertical-spacing-in-the-algorithm-environment

3. 小结

以上。
创作结束时间:2022年9月28日23:37:33

LaTeX Algorithm相关写法相关推荐

  1. latex 图片相关设置

    latex 图片相关设置 基本格式: \begin{figure}[图片位置设置] 图片格式(左对齐,居中,右对齐等) \includegraphics[图片大小]{图片存放位置} \twofigur ...

  2. LaTeX中的特殊符号,数学公式符号的相关写法

    文章目录 前言 1.有关特殊符号 symbols 2.有关数学公式相关的符号 mathematical symbols 小结 前言 创作开始时间:2021年7月23日13:39:12 有时候需要在La ...

  3. LaTeX数学公式相关

    Day 1 A Bite of LaTeX\LaTeXLATE​X May, 11th, 2020 第一次写这个东西,也不知道能够坚持多久的说(* ̄3 ̄)╭, 总之每天有时间就随便写写吧,一次就一个t ...

  4. latex中希腊字母写法

    1. 小写希腊字母 字母 Latex写法 字母 Latex写法 α\alphaα \alpha β\betaβ \beta γ\gammaγ \gamma δ\deltaδ \delta ϵ\epsi ...

  5. latex algorithm 引用格式错误

    问题: 写论文时,用到一个算法框架,形式如下: \begin{algorithm} \caption{1D-Floodfill算法} \LinesNumbered \KwIn{$\boldsymbol ...

  6. Latex 排版相关(一)

    目录 一.图 上下间距 图像高清插入 二.表 上下间距和字号 表格脚标 三.公式 公式组 设置公式字号 四.排版相关 设置一级标题和子标题的上下间距(全局设置) 设置全文的行间距 平衡双栏排版,页为对 ...

  7. latex 集合相关符号:实数集,整数集,并,包含,真包含

    一些特殊的集合符号,使用 \mathbb 命令: \mathbb{R} 或 \mathbb R:     \begin{equation}\mathbb R\end{equation} \mathbb ...

  8. Latex Algorithm 没有加粗

    来源 写个 algorithm 流程,但是在 怎么设置以及换不同 algorithm 包 都导致 伪代码 开头的 "Algorithm" 不加粗. 解决方式 更换多个包以及copy ...

  9. Latex algorithm

    方式一 需要包含的 \usepackage[noend]{algpseudocode} \usepackage{algorithmicx,algorithm} 源码 \begin{algorithm} ...

最新文章

  1. LeetCode 929 Unique Email Addresses--python一行解法,Java解法
  2. fetchsize jdbc_MySQL JDBC FetchSize解析
  3. 疯狂python讲义视频 百度云-每周一书《疯狂Python讲义》分享!
  4. c语言ascii码表数字,求教!我想显示数字但是现在显示的却是数字在ASCII码中对应的符...
  5. LeetCode(28): 实现strStr()
  6. React开发(123):ant design学习指南
  7. scanf 输入十六进制_在C语言中使用scanf()输入一个十六进制值
  8. 关于二叉树路径的遍历和处理
  9. 彻底搞懂Scrapy的中间件(二)
  10. 电音插件auto_Antares 发布新型人声制作插件 Auto-Tune EFX +
  11. 内网计算机ip地址查询,内网ip地址怎么查看_怎么查看内网ip地址_如何查看电脑的内网IP地址...
  12. c语言实验报告总结周信东,周信东主编c语言程序设计基础实验一实验报告精选版.docx...
  13. Unity实用案例之——喷漆效果
  14. 小米MIX 2获取root超级权限的经验
  15. python3 爬取今日头条文章(巧妙避开as,cp,_signature)
  16. Nginx stream 配置代理(Nginx TCP/UDP 负载均衡)
  17. 喜茶奶茶技术培训哪里学?
  18. 难过!能不能放下抢票套路,我只想买好好回家过年!我在网上抢火车票:多加了100元的加速包,却依然买不到票...
  19. asp医院病历管理系统
  20. strace命令使用方式

热门文章

  1. MATLAB字符串拼接编写y=a1x1+a2x2+……+anxn多元一次方程
  2. 程序地址空间:虚拟地址原理及发展过程(图解说明)
  3. 如何直接获取绝大部分网站的顶部title栏图标、logo(非js获取)
  4. word中grammarly消失的解决
  5. 关于python和speech
  6. 非计算机专业的大学生有必要考全国计算机等级证书吗?
  7. 新书推介:关宏志丨《路上的远影》
  8. 所有国家的信息数据(包含图片对应、区号前缀、国家名字、国家缩写)js、ts
  9. PowerDesigner反向工程PostgreSQL数据库
  10. python permission denied怎么解决_Permission denied的解决办法