[Tex/LaTex] cref table caption: works in body, not in lot

clevereftable of contents

I am using cleveref package. In one of my table, i'm refering to an equation in the text. The reference works fine (also hyperref) in the caption just below the table. Unfortunately it doesn't work in the list of tables and I get the traditional ?? in my pdf output together with the following warning:

LaTeX Warning: cref reference format for label type 'equation' undefined on in

Some piece of code (I hope sufficiently):

\documentclass[en,printlayout]{udesoftec}
\usepackage{cleveref}
\begin{document}
\frontmatter
\mainmatter
\part{Part1}
\begin{align}
\label{eq:CDF}
        D_{fit}(x) =& \sum_{i=1}^{N-1} \frac{1}{2}K_i\left(1+erf(\frac{x-m_i}{\sqrt{2}\sigma_i})\right)\nonumber \\
         &+  \frac{1}{2}(1-\sum_{i=1}^{N-1}K_i)\left(1+erf(\frac{x-m_N}{\sqrt{2}\sigma_N})\right)
\end{align}

\part{Part2}
\begin{table}[htbp]
\begin{tabular*}{\hsize}{@{\extracolsep{\stretch{1}}} c  c  c  c }
    \hline
\rule{0pt}{3ex} $i$ & $K $& $m$ & $\sigma$  \\
    \end{tabular*}
    \caption{$i$, $K$, $m$ and $\sigma$ correspond to the parameters in  \cref{eq:CDF}}
    \label{tab:myTab}
\end{table}
\end{document}

The class can be found on CTAN: http://www.ctan.org/pkg/udesoftec

I have already tried to delete the .lot file and compile twice without success. Any idea?

Thanks

Best Answer

The diagnosis by Jean-S├ębastien Gosselin is correct: the udesoftec class abuses \AtBeginDocument for typesetting material, which is not a good thing to do, see this answer by Heiko Oberdiek

The problem is that cleveref has to defer several of its tricks at begin document, but these will happen after some material has already been typeset, in particular the list of tables.

Fortunately there is a hook that can be used to transfer the material erroneously executed at begin document to \AfterEndPreamble, as suggested by Heiko. The maintainers of the class should be made aware of the problem.

I also fixed the equation, please look at it: the correct environment to use is multline and several small adjustments are also necessary; the main one is defining an operator for the error function.

\documentclass[en,printlayout]{udesoftec}
\usepackage{etoolbox}
\usepackage{cleveref}

\DeclareMathOperator{\erf}{erf}

%%% the hack!
\def\udesoftecoverride#1\mainmatter{%
  \AfterEndPreamble{#1\mainmatter}%
}
%%%

\begin{document}
\frontmatter
\mainmatter
\part{Part1}
\begin{multline}
\label{eq:CDF}
D_{\mathrm{fit}}(x) = 
  \sum_{i=1}^{N-1} 
    \frac{1}{2}K_i
    \left(1+\erf\Bigl(\frac{x-m_i}{\sqrt{2}\,\sigma_i}\Bigr)\right) \\
  + \frac{1}{2}\biggl(1-\sum_{i=1}^{N-1}K_i\biggr)
    \left(1+\erf\Bigl(\frac{x-m_N}{\sqrt{2}\,\sigma_N}\Bigr)\right)
\end{multline}

\part{Part2}
\begin{table}[htbp]
\begin{tabular*}{\hsize}{@{\extracolsep{\stretch{1}}} c  c  c  c }
    \hline
\rule{0pt}{3ex} $i$ & $K $& $m$ & $\sigma$  \\
    \end{tabular*}
    \caption{$i$, $K$, $m$ and $\sigma$ correspond to the parameters in  \cref{eq:CDF}}
    \label{tab:myTab}
\end{table}
\end{document}

enter image description here

The fixed equation

enter image description here

Related Question