# cref table caption: works in body, not in lot

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

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}


## The fixed equation

• @Wli If you are wanting to modify the class file, just change \AtBeginDocument at line 1188 into \AfterEndPreamble (the class already loads etoolbox). – egreg May 13 '15 at 22:03
• just released udesoftec v1.4.6 fixes this behavior according to changelog – NextThursday May 15 '15 at 9:01

I believe the problem comes from the fact that the package cleveref is loaded after the \listoftables has been defined within the \AtBeginDocument at the end of the documentclass udesoftec.

I do not know of any hack that would allow you to solve this issue directly from within your Tex file. Maybe a possible solution would be to use a local version of the file udesoftec.cls and add the line \usepackage(cleveref) right before \AtBeginDocument is defined.

Doing the above and running your MWE results in a listoftable which displays correctly the reference to eq.(0.1):

• Merci! I thought of something like this but everytime I dig into a .cls file I get lost and just want to keep writting my report. So I actualy changed to manual input (e.g. :"eq. \eqref"). I know it's not very TeX-like but it did the job. I'll input the cleveref inside the .cls file as it might happen again. – Wli May 13 '15 at 21:44