2009-09-28 8 views
3

je la commande newenvironment suivante:étiquette newenvironment latex

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

et je l'utilise thusly

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

Cependant, chaque fois que je référence l'étiquette (\ ref {eq: blabbing}), Je reçois un "1", au lieu d'un "1.1".

Quelqu'un pourrait-il me faire savoir ce que je fais mal?

Merci

Répondre

3

Vous y êtes presque, il vous suffit de redéfinir \thealgoctr aussi bien , quelque chose comme: (. Untested)

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

Et puis utilisez \thealgoctr dans votre environnement plutôt que explicitement réfé aller aux compteurs.

1

Je ne sais pas au sujet de votre comptoir, mais je peux recommander une autre possibilité où cela fonctionne:

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