1

I'm trying to write my first pseudocode algorithm with MikTEX and algorithm2e package but there are at least two things that I cannot understand. The image below shows what I want to achieve in term of final result.

First of all, I can't understand how to put the function name as the first line. I've tried with \caption and in other ways but I couldn't get rid of the text "Algorithm 1". The second thing that I want to learn is: how can I declare a variable with its type? i.e RBNode y?

enter image description here

EDIT

Trying to make the question more clear:

  1. How can I obtain an header (the first line of the image below) like this in the image below? I want that the text between the two black line contains only the function name and the list of parameters
Bender
  • 111

1 Answers1

1

To start with, you can rename the word "Algorithm" to anything you want using

\SetAlgorithmName{Something}{List of Somethings}

But that doesn't remove it. So instead you could give an empty string:

\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
...
\SetAlgorithmName{}{List of Algorithms}
\begin{algorithm}
    RBNode $y \gets x$, right\\
    \caption{rotateLeft (RBNode $x$)}
\end{algorithm}

which produces this:

eg1

Though the number still remains in the header.

Another thing you can try is adding the figure option (and remove ruled if you want) to \usepackage which removes the entire line where "Algorithm 1" was. But then you'll have to write your function name as a line of code rather than in the caption (which is probably better anyways):

\usepackage[linesnumbered,vlined,figure]{algorithm2e}
\newcommand{\FuncCall}[2]{\texttt{\bfseries #1(#2)}}
\SetKwProg{Function}{function}{}{}
...
\begin{algorithm}
    \Function{rotateLeft(RBNode $x$)}{
        RBNode $y \gets x$, right\\
        more\\
        code\\
        here\\
    }
    \caption{Some caption here}
\end{algorithm}

which produces this:

enter image description here

For more formatting tips, this answer is a good place to start: https://tex.stackexchange.com/a/534197/49045

And documentation for algorithm2e is at https://hal.inria.fr/file/index/docid/680365/filename/algorithm2e.sty

MD004
  • 1,226