Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

latex newenvironment label

Tags:

latex

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

like image 621
Dervin Thunk Avatar asked Oct 28 '25 07:10

Dervin Thunk


2 Answers

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.

like image 123
Will Robertson Avatar answered Oct 31 '25 01:10

Will Robertson


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}
like image 31
andre-r Avatar answered Oct 31 '25 01:10

andre-r



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!