[Tex/LaTex] Can be used only in preamble occurs when using \usepackage command

algorithm2eerrorssubfloats

Whenever I am trying to use the subfigure or the algorithm2e package using \usepackage command, it is showing

LaTeX Error: Can be used only in preamble. 

What is the problem and how to get rid of it. If there is any substitute for the two packages without using the above ones, kindly let me know.

Best Answer

If your document looks like

\documentclass{article}

\begin{document}

\usepackage{subfigure}

\end{document}

then you get the error

! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.5 \usepackage
               {subfigure}
? 

showing that the problem is the \usepackage on line 5, which should be in the preamble (that is, before \begin{document}0 so changing the file to

\documentclass{article}

\usepackage{subfigure}

\begin{document}

\end{document}

it runs without error.

Related Question