6

ラテックス内の自己定義環境へのラベルと対応する参照をどのように定義できますか?

例:

\newcounter{fpcounter}
\newenvironment{fp}[2]
{
\stepcounter{fpcounter}
\label{#1}
\textbf{Problem~\arabic{fpcounter}}
}
{}

ただし、含まれているラベルへの参照は、周囲のセクション/サブセクション/段落にリダイレクトされます。

ヒントはありますか?どうもありがとう。

4

1 に答える 1

9

\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}
于 2011-10-17T17:51:23.857 に答える