在哪里复制 algpseudocode.sty 包

在哪里复制 algpseudocode.sty 包

我对 LaTeX 完全陌生。让我说说我的问题。

我已经安装了TexStudio,之后我获取了论文模板并使用textstudio对其进行了编辑。

如果我想在模板中编写伪代码,我已经下载了 algpseudocode.sty 并将其复制到模板中,min.tex 位于该模板中。但我在编辑器中收到“只能在前言中使用”错误。我需要将此文件复制到 textstudio 中的某个地方还是其他地方?

我正在使用windows7。

我正在使用以下代码进行测试

\usepackage{algpseudocode}

\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}

错误:

Can be used only in preamble. \usepackage
Environment algorithm undefined. \begin{algorithm}
Package caption Error: \caption outside float \caption
Environment algorithmic undefined. \begin{algorithmic}
Undefined control sequence \Procedure
Undefined control sequence \Procedure{Euclid}{$a,b$}\Comment
Undefined control sequence \State
Undefined control sequence \While
Undefined control sequence \While{$r\not=0$}\Comment
Undefined control sequence \State
Undefined control sequence \State
Undefined control sequence \State
Undefined control sequence \EndWhile
Undefined control sequence \State
Undefined control sequence \State \textbf{return} $b$\Comment
Undefined control sequence \EndProcedure
\begin{document} ended by \end{algorithmic}. \end{algorithmic}
\begin{document} ended by \end{algorithm}. \end{algorithm}
Underfull \hbox (badness 10000) in paragraph
Difference (3) between bookmark levels is greater (hyperref) than one, level fixed

答案1

编译成功。请注意,该algorithm包是必需的,因为它提供了algorithm环境

\documentclass[a4paper]{article}

\usepackage{algpseudocode,algorithm}

\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}

相关内容