views:

683

answers:

2

I have the following newenvironment command:

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

and I use it thusly

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

However, every time I reference the label (\ref{eq:blabbing}), I get a "1", instead of a "1.1".

Could someone kindly let me know what I'm doing wrong?

Thanks

+1  A: 

I don't know about your counter, but I can recommend another possibility in which this works:

\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}
andre-r
+2  A: 

You're almost there, you just need to redefine \thealgoctr as well, something like:

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

(Untested.) And then use \thealgoctr in your environment rather than explicitly referring to the counters.

Will Robertson