![如何在算法中添加行号项目符号](https://linux22.com/image/394930/%E5%A6%82%E4%BD%95%E5%9C%A8%E7%AE%97%E6%B3%95%E4%B8%AD%E6%B7%BB%E5%8A%A0%E8%A1%8C%E5%8F%B7%E9%A1%B9%E7%9B%AE%E7%AC%A6%E5%8F%B7.png)
答案1
我刚刚复制了一些示例代码, 用过的这个答案简化使用和加载,tikzpagenodes
以便能够将星号放置在文本区域之外以到达
\documentclass{article}
\usepackage[ruled,linesnumbered]{algorithm2e}
\usepackage{tikzpagenodes}
\usetikzlibrary{shapes.geometric,tikzmark}
\newcounter{tmkcount}
\tikzset{use tikzmark/.style={
remember picture,
overlay,
execute at end picture={
\stepcounter{tmkcount}
},
},
tikzmark suffix={-\thetmkcount}
}
\begin{document}
\begin{algorithm}[ht]
\SetAlgoLined % from https://tex.stackexchange.com/a/359622/121799
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
read current\;
\eIf{understand}{
\tikzmark{star}go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}
\begin{tikzpicture}[use tikzmark]
\path (pic cs:star) coordinate (aux)
(current page text area.west|-aux)
node[anchor=east,star,star point ratio=2,draw,fill=yellow,inner sep=.2em,
yshift=.2em]{};
\end{tikzpicture}
\end{document}