I am currently working on runtime in my algorithm. I have currently set the algorithm up, and it looks like the following:
I need to insert 2 new columns beside the current text. Each column should be able to hold some text, so that it would look like the following:
How would I go around doing this?
My current code can be seen below:
\begin{algorithm}
\caption{Insertion-Sort køretid}\label{AlgRun}
\begin{algorithmic}[1]
\Procedure{insertion-sort}{$A,n$}
\State $inversions = 0$
\State \textit{L}[0..\textit{n} - 1] be a new array.
\For{q=0}{n-1}
\State L[q] = A[q]
\EndFor
\For{j=1}{n-1}
\State $key = L[j]$
\State $i = j - 1$
\While{$ i \geq 0$ \textbf{and} $L[i] > key$}
\State L[ i + 1] = L[ i ]
\State $j = i - 1$
\State $inversions = inversions + 1$
\EndWhile
$L[i + 1] = key$
\EndFor
\Return{inversions}
\EndProcedure
\end{algorithmic}
\end{algorithm}
Best Answer
The
algorithmicx
package provides a\Comment
command which does what you need, and is customizable. In this example I've created a macro with two arguments, one for each column of the annotation. Then each line gets inserted with a\Comment
command. I've also redefined the standard\Comment
format macro (\algorithmiccomment
) with the\algrenewcommand
macro to remove the arrow that shows up by default.