【问题标题】:Label not working inside a \newcommand with a custom Float in LaTeX标签在 LaTeX 中使用自定义浮点数在 \newcommand 内不起作用
【发布时间】:2018-04-11 07:38:47
【问题描述】:

我声明了一个包含\caption\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 ??)"

我知道之前已经问过类似的问题,但它与新环境无关。 How to reference a label within a newcommand in LATEX?

【问题讨论】:

    标签: latex latex-environment


    【解决方案1】:

    我发现\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 !
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-04
      • 2015-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多