gpt4 book ai didi

latex - latex 自创环境的引用

转载 作者:行者123 更新时间:2023-12-04 18:15:02 31 4
gpt4 key购买 nike

如何在 Latex 中定义标签和对自定义环境的相应引用?

例子:

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

尽管如此,对包含标签的任何引用都会被重定向到周围的部分/小节/段落。

任何提示?
非常感谢。

最佳答案

使用 \refstepcounter而不是 \stepcounter .这设置了什么\label命令将使用并重新定义 thefpcounter\renewcommand{\thefpcounter}{\arabic{fpcounter}} .这产生

enter image description here

此外,还提供了一些其他选项,具体取决于您希望如何标记自定义环境。

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

关于latex - latex 自创环境的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5125906/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com