3

I cannot seem to get any of the LaTeX pseudocode packages to work correctly on my computer. For example, if I run this block of code:

\documentclass{article}
\usepackage{algorithm}% http://ctan.org/pkg/algorithm
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx

\begin{document}
\begin{algorithm}
\caption{Euclid’s algorithm}\label{euclid}
\begin{algorithmic}[1]
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
   \State $r\gets a\bmod b$
   \While{$r\not=0$}\Comment{We have the answer if r is 0}
      \State $a\gets b$
      \State $b\gets r$
      \State $r\gets a\bmod b$
   \EndWhile\label{euclidendwhile}
   \State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\end{algorithm}

\end{document}

I get the following error message:

./pseudocode.tex:7: LaTeX Error: \caption outside float.

l.7 \caption {Euclid’s algorithm}\label{euclid}

Edit: I have tried loading the caption.sty package directly but with no success. Here is the .log file as requested.

> This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012)
> (format=pdflatex 2012.6.30)  11 SEP 2012 16:36 entering extended mode 
> restricted \write18 enabled.  file:line:error style messages enabled. 
> %&-line parsing enabled.
> **pseudocode.tex (./pseudocode.tex LaTeX2e <2011/06/27> Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, ge
> rman-x-2012-05-30, ngerman-x-2012-05-30, afrikaans, ancientgreek,
> ibycus, arabi c, armenian, basque, bulgarian, catalan, pinyin, coptic,
> croatian, czech, danis h, dutch, ukenglish, usenglishmax, esperanto,
> estonian, ethiopic, farsi, finnis h, french, friulan, galician,
> german, ngerman, swissgerman, monogreek, greek, h ungarian, icelandic,
> assamese, bengali, gujarati, hindi, kannada, malayalam, ma rathi,
> oriya, panjabi, tamil, telugu, indonesian, interlingua, irish,
> italian,  kurmanji, latin, latvian, lithuanian, mongolian,
> mongolianlmc, bokmal, nynorsk,  polish, portuguese, romanian, romansh,
> russian, sanskrit, serbian, serbianc, s lovak, slovenian, spanish,
> swedish, turkish, turkmen, ukrainian, uppersorbian,  welsh, loaded.
> (/usr/local/texlive/2012/texmf-dist/tex/latex/base/article.cls
> Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
> (/usr/local/texlive/2012/texmf-dist/tex/latex/base/size10.clo File:
> size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option) )
> \c@part=\count79 \c@section=\count80 \c@subsection=\count81
> \c@subsubsection=\count82 \c@paragraph=\count83
> \c@subparagraph=\count84 \c@figure=\count85 \c@table=\count86
> \abovecaptionskip=\skip41 \belowcaptionskip=\skip42
> \bibindent=\dimen102 ) (./algorithm.sty \c@algorithm=\count87
> \Blockindent=\skip43 \algorithmindent=\skip44 ) (./algpseudocode.sty
> Package: algpseudocode 
> 
> (/usr/local/texlive/2012/texmf-dist/tex/latex/base/ifthen.sty Package:
> ifthen 2001/05/26 v1.1c Standard LaTeX ifthen package (DPC) )
> (/usr/local/texlive/2012/texmf-dist/tex/latex/algorithmicx/algorithmicx.sty
> Package: algorithmicx 2005/04/27 v1.2 Algorithmicx
> 
> Document Style algorithmicx 1.2 - a greatly improved `algorithmic'
> style \c@ALG@line=\count88 \c@ALG@rem=\count89 \c@ALG@nested=\count90
> \ALG@tlm=\skip45 \ALG@thistlm=\skip46 \c@ALG@Lnr=\count91
> \c@ALG@blocknr=\count92 \c@ALG@storecount=\count93
> \c@ALG@tmpcounter=\count94 \ALG@tmplength=\skip47 ) Document Style -
> pseudocode environments for use with the `algorithmicx' style )
> (./pseudocode.aux) \openout1 = `pseudocode.aux'.
> 
> LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line
> 5. LaTeX Font Info:    ... okay on input line 5. LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 5. LaTeX Font Info:   
> ... okay on input line 5. LaTeX Font Info:    Checking defaults for
> OT1/cmr/m/n on input line 5. LaTeX Font Info:    ... okay on input
> line 5. LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on
> input line 5. LaTeX Font Info:    ... okay on input line 5. LaTeX Font
> Info:    Checking defaults for OMX/cmex/m/n on input line 5. LaTeX
> Font Info:    ... okay on input line 5. LaTeX Font Info:    Checking
> defaults for U/cmr/m/n on input line 5. LaTeX Font Info:    ... okay
> on input line 5.
> 
> 
> ./pseudocode.tex:7: LaTeX Error: \caption outside float.
> 
> See the LaTeX manual or LaTeX Companion for explanation. Type  H
> <return>  for immediate help.  ...                                    
> 
>                                                    l.7 \caption
>             {Euclid�s algorithm}\label{euclid} ?  ./pseudocode.tex:7: Emergency stop.  ...                                              
>                                                    l.7 \caption
>             {Euclid�s algorithm}\label{euclid} You're in trouble here.  Try typing  <return>  to proceed. If that doesn't work, type  X
> <return>  to quit.
> 
>   Here is how much of TeX's memory you used:  735 strings out of
> 493488  9692 string characters out of 3141326  56474 words of memory
> out of 3000000  4115 multiletter control sequences out of 15000+200000
> 4294 words of font info for 16 fonts, out of 3000000 for 9000  957
> hyphenation exceptions out of 8191  27i,0n,18p,256b,102s stack
> positions out of 5000i,500n,10000p,200000b,50000s ./pseudocode.tex:7: 
> ==> Fatal error occurred, no output PDF file produced!
1
  • Not only works fine on me for me, but looks good. Win7/TeXLive2012
    – Canageek
    Commented Sep 12, 2012 at 0:45

1 Answer 1

2

Delete algorithm.sty and algpseudocode.sty from your working folder and recompile. This should allow LaTeX to find the correct versions in your TeX Directory Structure/TDS. In the very least, algorithm.sty should load the float package, which your "local version" does not...

1
  • fixed my problem by this simple solution after an hour searching in google... Thanks man!
    – ARH
    Commented Nov 7, 2014 at 0:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .