Minipage – How to Put an Algorithm in Minipage

algorithmsminipage

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}

Best Answer

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.