有没有一个算法包可以让我实现算法的风格,即每个数字都在算法中的圆圈内?我对用圆圈数字对步骤进行编号特别感兴趣。
%%%% ijcai21.tex
\typeout{IJCAI--21 Instructions for Authors}
% These are the instructions for authors for IJCAI-21.
\documentclass{article}
\pdfpagewidth=8.5in
\pdfpageheight=11in
% The file ijcai21.sty is NOT the same than previous years'
\usepackage{ijcai21}
% Use the postscript times font!
\usepackage{times}
\usepackage{soul}
\usepackage{url}
\usepackage[hidelinks]{hyperref}
\usepackage[utf8]{inputenc}
\usepackage[small]{caption}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{booktabs}
\usepackage{algorithm}
\usepackage{algorithmic}
\urlstyle{same}
\newtheorem{example}{Example}
\newtheorem{theorem}{Theorem}
\title{}
\begin{document}
\maketitle
\begin{algorithm}[tb]
\caption{algorithm}
\label{alg:algorithm}
\textbf{Input}: Your Input\\
\textbf{Output}: Your output\\
\begin{algorithmic}[1] %[1] enables line numbers
\STATE a = first \\
\STATE b = second\\
\STATE sum = first - second\\
\end{algorithmic}
\end{algorithm}
\end{document}
答案1
您必须更改要圈出的数字的格式:
\documentclass{article}
\usepackage{algorithm,algorithmic}
\usepackage{circledsteps}% https://tex.stackexchange.com/q/7032/5764
\newcommand{\circlenum}[3]{\Circled{\small #1{#2}}}
\algsetup{linenosize=\circlenum}
\begin{document}
\begin{algorithm}
\caption{An algorithm}
\begin{algorithmic}[1]
\STATE First statement
\STATE Second statement
\STATE Third statement
\end{algorithmic}
\end{algorithm}
\end{document}
行号的构造algorithmic
分为 4 个部分:
- 行号字体
- 行号表示
- 行数计数器
- 行号分隔符
上述方法更新了字体宏 (1),以获取所有剩余参数,并仅使用计数器及其表示 - (2) 和 (3),丢弃分隔符(因为不需要)。这就是为什么您只能在宏中看到#1
and,即使它被定义为具有/接受 3 个参数。最后一个参数 - 行分隔符 - 被吞噬了。#2
\circlenum
要将algorithmic
计数器从 0 而不是 1 启动,请使用以下补丁:
\usepackage{xpatch}
\xpatchcmd{\algorithmic}% <cmd>
{\setcounter{ALC@line}{0}}% <search>
{\setcounter{ALC@line}{-1}}% <replace>
{}{}% <success><failure>