与此类似问题,我有这个最小的工作代码:
\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}
\caption{Some alg}
\begin{algorithmic}[1]
\REQUIRE a,b, c
\STATE d = a + b + c
\STATE d = d/2
\STATE d = d/3
\RETURN d
\end{algorithmic}
\end{algorithm}
\end{document}
我想要的是将步骤编号为罗马数字(而不是阿拉伯数字)。
我尝试过的:
答案1
环境中的行号algorithmic
使用计数器ALC@line
。不幸的是,该计数器没有记录,并且其打印格式被硬编码为\arabic
。
在以下示例中,
\theALC@line
取代\arabic{ALC@line}
\setAlgoLinenoFormat{<an one-arg macro>}
提供了,因此\setAlgoLinenoFormat{\roman}
将行号设置为罗马数字。
\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{xpatch}
\makeatletter
% patch env "algorithmic" to use \the<lineno counter>
\xpatchcmd\algorithmic
{\ALC@linenosize \arabic{ALC@line}\ALC@linenodelimiter}
{\ALC@linenosize \theALC@line\ALC@linenodelimiter}
{}{\fail}
% use roman line numbers
\newcommand\setAlgoLinenoFormat[1]{%
\renewcommand*{\theALC@line}{#1{ALC@line}}}
\makeatother
\begin{document}
\begin{algorithm}
\caption{Some alg}
\begin{algorithmic}[1]
\setAlgoLinenoFormat{\roman}
\REQUIRE a,b, c
\STATE d = a + b + c
\STATE d = d/2
\STATE d = d/3
\RETURN d
\end{algorithmic}
\end{algorithm}
\begin{algorithm}
\caption{Some alg}
\begin{algorithmic}[1]
\setAlgoLinenoFormat{\Roman}
\REQUIRE a,b, c
\STATE d = a + b + c
\STATE d = d/2
\STATE d = d/3
\RETURN d
\end{algorithmic}
\end{algorithm}
\end{document}