3

I have the following LaTeX code

 \documentclass{article}
 \usepackage[ruled]{algorithm2e}
 \begin{document}

     \begin{algorithm}
        do something\;
     \caption{Algorithm #1}
     \end{algorithm}

     \begin{algorithm}
        do something\;
     \caption{Algorithm #2}
     \end{algorithm}

     \begin{algorithm}
        do something\;
     \caption{Algorithm #3}
     \end{algorithm}

 \end{document}

Given that I have initialised algorithm2e with the "ruled" option, the three algorithms appear with a nice ruled frame.

I want the second algorithm to appear with no frame at all, that is, just plain code. Is there a way to achieve this?

Thanks.

1 Answer 1

1

These options are set when loading the package and is meant to promote consistency. However, it's fairly trivial to adjust the algorithm style.

Below I've introduced \algorithmstyle{<style>} where you can specify/update the algorithm style to match any of the existing ones provided by the package:

enter image description here

\documentclass{article}
\usepackage[ruled]{algorithm2e}
\makeatletter
\newcommand{\algorithmstyle}[1]{\renewcommand{\algocf@style}{#1}}
\makeatother
\begin{document}

\begin{algorithm}
  do something\;
\caption{Algorithm A}
\end{algorithm}

\algorithmstyle{plain}
\begin{algorithm}
  do something\;
\caption{Algorithm B}
\end{algorithm}

\algorithmstyle{ruled}
\begin{algorithm}
  do something\;
\caption{Algorithm C}
\end{algorithm}

 \end{document}

Default style choices include plain, plainruled, boxed, ruled, algoruled, boxruled and tworuled.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.