I was curious... I couldn't find this in any of the documentation of the algorithm2e and algorithmicx packages. I'm wondering if there's a way to represent objects with attributes in LaTeX. Would help a lot.


1 Answer 1


You can extend algorithmicx to include, say, C-like struct. A minimal working example:


\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

\caption*{Example of a C-like struct}
\begin{algorithmic}%[1] % uncomment for line numbers
  \State $id$ : \textsc{uuid}
  \State $name$ : \textsc{String}

The only caveat is, anonymous structs aren't adequately supported in this setup.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.