如何在算法中添加行号项目符号

如何在算法中添加行号项目符号

我想在行号旁边添加一个项目符号,如下图所示。我该怎么做?

在此处输入图片描述

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

在此处输入图片描述

相关内容