How do I add columns to an algorithm using the "algo" package?


I’m using the “algo” package and I’d like to know if there’s a way to modify it to achieve something like the image. If not, I’d like to know if there’s another way. Thank you very much!

Here is the code for the algorithm I made with the “algo” package.

#import "@preview/algo:0.3.6": algo, i, d, comment, code
#set text(font: "New Computer Modern", size: 11pt)

= Test
#algo(
  title: "INSERTION-SORT",
  parameters: ("A","n"),
  block-align: left
)[
  for $i = 2$ to $n$: #i \ 
  key = $A[i]$ \ 
  #comment(inline: true)[Insert A[i] into the sorted subarray A[1:i-1]] \
  $j = i - 1$ \
  while $j > 0$ and $A[j] >$ key: #i \
    $A[j + 1] = A[j]$ \
    $j = j - 1$ #d \
    $A[j + 1] =$ key
]

The algo package uses a table internally, see typst-algorithms/algo.typ at main · platformer/typst-algorithms · GitHub. Adding the cost and times column would require a modification of the package source code, but it is probably still easier than trying to write something from scratch.

I quickly looked at the other packages that come up when you search for algorithm in the Typst Universe, but none of them showed your use case in the examples.

2 Likes

Thanks, I’ll see if I understand the package. It was my last, last option, but I have no other choice.

You could also submit feature request to the package author. If your use case is well described, perhaps this could also be useful for other users.