0

我声明了一个包含 a\caption和 a的新环境,\label所以我可以引用它。

在我的标题中:

\DeclareFloatingEnvironment[name=Tableau]{tableau}
\newenvironment{ptab}{\captionsetup{type=tableau}}{}

在我的 .tex 文件中:

\begin{ptab}
    \caption{A caption for my table}
    \label{ptab:myTab}
\end{ptab}

Some text with a reference (Tableau~\ref{ptab:myTab}) % Works fine !

问题:我想通过声明一个\newcommand可以为我写这个来获得一些时间。但是文本中的引用不再起作用了!

在我的标题中添加:

\newcommand{\tabref}[2]{%
    \begin{ptab} 
        \label{#1} 
        \caption{#2} 
    \end{ptab}}

在 .tex 文件中:

\tabref{ptab:myTab}{A caption for my table}

Some text with a reference (Tableau~\ref{ptab:myTab}) % Not working "(Tableau ??)"

我知道之前已经问过类似的问题,但它与新环境无关。 如何在 LATEX 的新命令中引用标签?

4

1 回答 1

0

我发现\label{}和的顺序\caption{}是颠倒的。这很重要,因为 LaTeX 需要先创建标题,然后才能用标签引用它。工作代码:

\newcommand{\tabref}[2]{%
    \begin{ptab}
        \caption{#2} 
        \label{#1}  
    \end{ptab}}

\tabref{ptab:myTab}{A caption for my table}

Some text with a reference (Tableau~\ref{ptab:myTab}) % Now working !
于 2018-04-17T06:42:31.470 回答