答案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}