Latex 如何在乳胶中引用新产品中的标签?
我已经创建了一个newcommand\figc来为我的文档快速创建数字。然而,我很难引用它。文档正在成功编译,但如图(?)所示 不要在Latex 如何在乳胶中引用新产品中的标签?,latex,Latex,我已经创建了一个newcommand\figc来为我的文档快速创建数字。然而,我很难引用它。文档正在成功编译,但如图(?)所示 不要在\label中使用fig:{1},而是使用fig:{1}: 文档中设置的内容与其内部表示形式之间存在差异。这就是为什么\label{fig:{abc}}不同于\label{fig:abc},因此可以提供未定义的引用。是\caption和\label的顺序重要吗?@KcFnMi:是的\label必须是\caption的一部分或在它之后。成为它的一部分意味着什么?@
\label
中使用fig:{1}
,而是使用fig:{1}
:
文档中设置的内容与其内部表示形式之间存在差异。这就是为什么
\label{fig:{abc}}
不同于\label{fig:abc}
,因此可以提供未定义的引用。是\caption
和\label
的顺序重要吗?@KcFnMi:是的\label
必须是\caption
的一部分或在它之后。成为它的一部分意味着什么?@KcFnMi:当你这样使用它时:\caption{Your caption\label{label}}
。
\newcommand{\figc}[3]{
\begin{figure}[H]
\centering
\includegraphics[width={#3}]{figures/{#1}.jpg}
\caption{{#2}}
\label{fig:{#1}}
\end{figure}
fig:{#1}} ----> However, this part is displayed correctly in the PDF as fig:samplefig
Here is a sample text to reference (Figure \ref{fig:samplefig}).
\figc{samplefig}{Sample Figure}{3in}
\documentclass{article}
\usepackage{float,graphicx}
\newcommand{\figc}[3]{%
\begin{figure}[H]
\centering
\includegraphics[width=#3]{#1.jpg}
\caption{#2}
\label{fig:#1}
\end{figure}
fig:#1% Set the reference as well
}
\begin{document}
Here is a sample text to reference (Figure \ref{fig:example-image}).
\figc{example-image}{Sample Figure}{3in}
\end{document}