8

I have the following algorithm. Could any one please let me know how I can put it in a minipage?

\begin{algorithm}\small
 {Start}\;
  \eIf{A is bigger than B}{
  \eIf{if A is bigger than C}{
 A;
 }{
C;
 }
}{
\eIf{B is bigger than C}{
B;   }{
C;
}
}
 \caption{A B C comparison}
 \end{algorithm}
7

Your issue is algorithm is a float environment by default, and you can't have floats inside a minipage. However, you can specify the [H] option to suppress floating and have it work as you intend:

\documentclass{article}
\usepackage{algorithm2e}

\begin{document}
    \begin{minipage}{.5\linewidth}
        \begin{algorithm}[H]\small
        {Start}\;
            \eIf{A is bigger than B}{
                \eIf{if A is bigger than C}{
                    A;
                }{
                    C;
                }
            }{
            \eIf{B is bigger than C}{
                B;   
            }{
                C;
            }
            }
        \caption{A B C comparison}
        \end{algorithm}
    \end{minipage}
\end{document}

enter image description here

In the future please include a MWE showing your \documentclass and \usepackage commands, helps people help you! I've never used algorythm2e so it took me a bit to find the right package.

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.