3

私は次の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 {eq:blabbing})を参照するたびに、「1.1」ではなく「1」が表示されます。

誰かが私が間違っていることを親切に教えてもらえますか?

ありがとう

4

2 に答える 2

3

もうすぐそこにいます。\thealgoctr次のように、再定義する必要があります。

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

(テストされていません。)次に\thealgoctr、カウンターを明示的に参照するのではなく、ご使用の環境で使用します。

于 2009-09-29T00:17:11.140 に答える
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}
于 2009-09-28T19:35:39.993 に答える