繁体   English   中英

如何在LATEX中的newcommand中引用标签?

[英]How to reference a label within a newcommand in LATEX?

我创建了一个新命令\\ 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}

不要在\\label使用fig:{#1} ,而应使用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}}\\label{fig:abc} ,因此可以提供未定义的引用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM