我很好奇...我在 algorithm2e 和 algorithmicx 包的任何文档中都找不到这个。我想知道是否有办法在 LaTeX 中用属性表示对象。会很有帮助。
答案1
你可以扩展algorithmicx
以包含 C-like struct
。一个最小的工作示例:
\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\algdef{SE}% flags used internally to indicate we're defining a new block statement
[STRUCT]% new block type, not to be confused with loops or if-statements
{Struct}% "\Struct{name}" will indicate the start of the struct declaration
{EndStruct}% "\EndStruct" ends the block indent
[1]% There is one argument, which is the name of the data structure
{\textbf{struct} \textsc{#1}}% typesetting of the start of a struct
{\textbf{end struct}}% typesetting the end of the struct
\begin{document}
\begin{algorithm}
\caption*{Example of a C-like struct}
\begin{algorithmic}%[1] % uncomment for line numbers
\Struct{Person}
\State $id$ : \textsc{uuid}
\State $name$ : \textsc{String}
\EndStruct
\end{algorithmic}
\end{algorithm}
\end{document}
唯一需要注意的是,此设置没有充分支持匿名结构。