我创建了一个newcommand \ figc来快速为我的文档创建数字。但是,我无法引用它。该文档正在成功编译,但显示为图(??)。
\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}
答案 0 :(得分:1)
请勿在{{1}}中使用fig:{#1}
,而是使用\label
:
fig:#1
文档中设置的内容与其内部表示之间存在差异。这就是\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}
与\label{fig:{abc}}
不同的原因,因此可以提供未定义的引用。