乳胶新环境标签

发布于 2024-08-06 05:20:32 字数 473 浏览 2 评论 0原文

我有以下 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” 。

有人可以让我知道我做错了什么吗?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月流歌 2024-08-13 05:20:32

你就快到了,你只需要重新定义 \thealgoctr ,就像:(

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

未经测试。)
然后在您的环境中使用 \thealgoctr 而不是显式引用计数器。

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.

隱形的亼 2024-08-13 05:20:32

我不知道你的计数器,但我可以推荐另一种可行的可能性:

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

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}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文