如何在乳胶中定义标签和对自定义环境的相应引用?
例子:
\newcounter{fpcounter}
\newenvironment{fp}[2]
{
\stepcounter{fpcounter}
\label{#1}
\textbf{Problem~\arabic{fpcounter}}
}
{}
尽管对包含标签的任何引用都会被重定向到周围的部分/小节/段落。
有什么提示吗?非常感谢。
使用\refstepcounter
而不是\stepcounter
. 这将设置\label
命令将使用的内容,并使用 重新thefpcounter
定义\renewcommand{\thefpcounter}{\arabic{fpcounter}}
。这产生
此外,还提供了一些其他选项,具体取决于您希望如何标记自定义环境。
\documentclass{book}
\newcounter{fpcounter}
%\renewcommand{\thefpcounter}{\thechapter.\arabic{fpcounter}}
%\renewcommand{\thefpcounter}{\thesection.\arabic{fpcounter}}
\renewcommand{\thefpcounter}{\arabic{fpcounter}}
\newenvironment{fp}[2]{%
\refstepcounter{fpcounter}%
\label{#1}%
\noindent\textbf{Problem~\thefpcounter}%
}%
{}%
\begin{document}
\chapter{Lorem}
\section{Ipsum}
\begin{fp}{fp:A}{}
content of environment 1
\end{fp}
\begin{fp}{fp:B}{}
content of environment 2
\end{fp}
\medskip\noindent
As shown in Problem~\ref{fp:A}, and Problem~\ref{fp:B}...
\end{document}