Latex label newenvironment

I have the following command newenvironment:

\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 that way

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

However, every time I refer to the label (\ ref {eq: blabbing}), I get "1", not "1.1".

Can someone kindly tell me what I'm doing wrong?

thanks

+3
source share
2 answers

You are almost there, you just need to override \thealgoctr, something like:

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

(tested.) And then use \thealgoctrin your environment, and not explicitly referring to counters.

+3
source

I do not know about your counter, but I can recommend one more possibility in which it 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}
+1
source

Source: https://habr.com/ru/post/1718734/


All Articles