ラテックス内の自己定義環境へのラベルと対応する参照をどのように定義できますか?
例:
\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}