2

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.