1

I am using the algorithm2e package to include a few algorithms in my document. A few of the algorithms are presented side-by-side, and I am not satisfied with how this looks with the bottom horizontal line. Preferably I would like to completely remove this line somehow, but I cannot seem to find any such option in the algorithm2e manual.

Any help would be greatly appreciated!

Here is an example of what it looks like:

enter image description here

And a minimal working example to produce the picture:

\documentclass[12pt, a4paper]{article}
\usepackage[ruled,vlined]{algorithm2e}
\begin{document}
  \begin{figure}[htp]
  \begin{minipage}[t]{8cm}
    \vspace{0pt}  
    \begin{algorithm}[H]
            \DontPrintSemicolon
            \KwData{$S, C$}
            \KwResult{$X$}
            \Begin{
                    $X \leftarrow \emptyset$\;
                    \While{$C \neq \emptyset$}{
                            $A \leftarrow$ arbitrary element in $C$\;
                            $a \leftarrow$ arbitrary element in $a$\;
                            $X \leftarrow X \cup \{a\}$\;
                            $C \leftarrow C \setminus \{A \in C\ |\ A \cap X \neq \emptyset\}$\;
                    }
                    \Return{$X$}\;
            }
            \caption{Alg-1}
    \end{algorithm}
  \end{minipage}
  \begin{minipage}[t]{8cm}
        \vspace{0pt}
        \begin{algorithm}[H]
            \DontPrintSemicolon
            \KwData{$S, C$}                  
            \KwResult{$X$}                  
            \Begin{
                    $X \leftarrow \emptyset$\;
                     \While{$C \neq \emptyset$}{
                            $A \leftarrow$ arbitrary element in $C$\;
                            $X \leftarrow X \cup A$ \;
                            $C \leftarrow C \setminus \{A \in C\ |\ A \cap X \neq \emptyset\}$\;
                      }
                      \Return{$X$}\;
            }                  
            \caption{Alg-2}
        \end{algorithm}
  \end{minipage}
  \end{figure}
\end{document}
1
  • @campa I'm sorry for the miss! It has been fixed now. Feb 20, 2021 at 18:28

1 Answer 1

2

I don't see directly an option for this so one must delve into algorithms2e. Luckily for you I've done this a couple of days ago for another answer, so I can still remember how it works :-)

\documentclass[12pt, a4paper, titlepage]{article}

\usepackage{geometry} % more generous margins

\usepackage[ruled,vlined]{algorithm2e}
\makeatletter
\renewcommand*{\@algocf@post@ruled}{}
\makeatother

\begin{document}

  \begin{figure}[htp]
  \begin{minipage}[t]{.48\linewidth}
    \vspace{0pt}  
    \begin{algorithm}[H]
            \DontPrintSemicolon
            \KwData{$S, C$}
            \KwResult{$X$}
            \Begin{
                    $X \leftarrow \emptyset$\;
                    \While{$C \neq \emptyset$}{
                            $A \leftarrow$ arbitrary element in $C$\;
                            $a \leftarrow$ arbitrary element in $a$\;
                            $X \leftarrow X \cup \{a\}$\;
                            $C \leftarrow C \setminus \{A \in C\ |\ A \cap X \neq \emptyset\}$\;
                    }
                    \Return{$X$}\;
            }
            \caption{Alg-1}
    \end{algorithm}
  \end{minipage}\hfill
  \begin{minipage}[t]{.48\linewidth}
        \vspace{0pt}
        \begin{algorithm}[H]
            \DontPrintSemicolon
            \KwData{$S, C$}                  
            \KwResult{$X$}                  
            \Begin{
                    $X \leftarrow \emptyset$\;
                     \While{$C \neq \emptyset$}{
                            $A \leftarrow$ arbitrary element in $C$\;
                            $X \leftarrow X \cup A$ \;
                            $C \leftarrow C \setminus \{A \in C\ |\ A \cap X \neq \emptyset\}$\;
                      }
                      \Return{$X$}\;
            }                  
            \caption{Alg-2}
        \end{algorithm}
  \end{minipage}
  \end{figure}

\end{document}

enter image description here

I've taken the liberty of changing the minipage setup a bit. Working with hard-coded lengths is often dangerous: better use multiples of \linewidth and some stretchable space.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .