簡體   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