2009-09-28 83 views
3

我有以下newenvironment命令:胶乳newenvironment标签

\newcounter{algoctr}[chapter] \setcounter{algoctr}{0} 
\newenvironment{algo}[1] { 
\refstepcounter{algoctr}\vspace{0.2cm}\noindent{\bf Algorithm 
\arabic{chapter}.\arabic{algoctr}: #1}}{\par} 

我用它正是如此

\begin{algo}{blabbing a blah} 
blah 
blah 
\label{eq:blabbing} 
\end{algo} 

然而,每次我参考标签(\ REF {当量:泄密}),我得到一个“1”,而不是“1.1”。

有人能让我知道我在做什么错吗?

感谢

回答

3

就快,你只需要重新定义\thealgoctr以及,是这样的:(未经测试)

\renewcommand\thealgoctr{\arabic{chapter}.\arabic{algoctr}} 

然后在您的环境中使用\thealgoctr而不是明确refe送到柜台。

1

我不知道你的柜台,但我可以推荐另一种可能性中,这个工程:

\usepackage{amsthm} 

\newtheoremstyle{algostyle} 
    {0.2cm}{0cm}%         margin top and bottom 
    {\rmfamily}%         text layout 
    {0cm}%          indention of header 
    {\bfseries}{ }%        header font and text after 
    {0cm}%          space after header 
    {\thmname{#1}\thmnumber{ #2}:\thmnote{ #3}}% header 

\theoremstyle{algostyle} 
\newtheorem{algo}{Algorithm}[chapter] 

\begin{algo}[blabbing a blah]% brackets instead of curly braces for note 
blah 
blah 
\label{eq:blabbing} 
\end{algo}