![用 LaTeX 编写伪代码](https://linux22.com/image/255255/%E7%94%A8%20LaTeX%20%E7%BC%96%E5%86%99%E4%BC%AA%E4%BB%A3%E7%A0%81.png)
我似乎无法让任何 LaTeX 伪代码包在我的计算机上正常工作。例如,如果我运行以下代码块:
\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}
我收到以下错误消息:
./pseudocode.tex:7: LaTeX 错误:\caption 超出浮点数。
l.7 \caption {欧几里得算法}\label{euclid}
编辑:我尝试caption.sty
直接加载包,但没有成功。这是.log
请求的文件。
> 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
从工作文件夹中删除algorithm.sty
并algpseudocode.sty
重新编译。这应该允许 LaTeX 找到正确的TeX 目录结构/TDS 中的版本。至少,algorithm.sty
应该加载float
包裹,而您的“本地版本”却没有……