First of all, this is not an incompatibility between caption
and threeparttablex
package. The caption
package only gives a hint that something is going wrong here, and it's correct about this.
But lets first start with the default implementation of \item
, offered by LaTeX2e itself:
\def\@item[#1]{%
...
\if@noitemarg
\@noitemargfalse
\if@nmbrlist
\refstepcounter\@listctr
\fi
\fi
...}
As one can see here, \item
will only produce a reference (which can be used by \ļabel
later on) if the list is numbered and \item
was used without optional argument. So especially \item[2]
will not generate a reference which can be used by \label
and \ref
. (This seems to be a design decision made by Leslie Lamport.)
Example document:
\documentclass{article}
\begin{document}
\ref{item1} \ref{item2}
\begin{enumerate}
\item \label{item1} Text
\item[2] \label{item2} Text
\end{enumerate}
\end{document}
Both \ref
will output 1
here (and not 1
and 2
) because only the \item
without optional argument is generating a reference, so both \label
are actually using the same reference created by the \item
without optional argument.
The threeparttablex
package redefines \item
(inside tablenotes
only), so \item[2]
will produce a reference (by defining \@currentlabel
): [1]
\renewcommand\tablenotes{%
\let\TPTL@item=\item
\renewcommand\item[1][]{\TPTL@item[##1]%
\phantomsection\protected@edef\@currentlabel{##1}}
...}
Example document:
\documentclass[letterpaper]{article}
\usepackage[referable]{threeparttablex}
\begin{document}
\begin{table}[ht]
\centering
\begin{threeparttable}
\begin{tabular}{|l|c|c|}
\hline
A & 1 & 2 \tnote{1} \\
\hline
B & 2 & 1 \\
\hline
C & 3 \tnotex{tn:2} & 3 \\
\hline
Line & producing & space. \\
\hline
\end{tabular}
\begin{tablenotes}
\item[1] This is the first note.
\item[2] \label{tn:2} This is the hyperlinked note.
\end{tablenotes}
\end{threeparttable}
\caption{A table caption.}
\end{table}
\end{document}
The outcome is fine, and \tnotex{tn:2}
will produce a 2
as expected. (Note: One can add the usage of the caption
package here without problems.)
Now we will add the usage of \renewlist{tablenotes}
offered by the enumitem
package:
\documentclass[letterpaper]{article}
\usepackage[referable]{threeparttablex}
\usepackage{enumitem}
\renewlist{tablenotes}{enumerate}{1}
\begin{document}
\begin{table}[ht]
\centering
\begin{threeparttable}
\begin{tabular}{|l|c|c|}
\hline
A & 1 & 2 \tnote{1} \\
\hline
B & 2 & 1 \\
\hline
C & 3 \tnotex{tn:2} & 3 \\
\hline
Line & producing & space. \\
\hline
\end{tabular}
\begin{tablenotes}
\item[1] This is the first note.
\item[2] \label{tn:2} This is the hyperlinked note.
\end{tablenotes}
\end{threeparttable}
\caption{A table caption.}
\end{table}
\end{document}
Upps, the 2
is gone now. What has happened?
Well, the \renewlist{tablenotes}{enumerate}{1}
re-defines the tablenotes
environment to use an ordinary enumerate
environment instead. And as we know from above \item[2]
inside an ordinary enumerate
environment will not generate a reference for usage with \label
at all, so this eliminats the feature offered by threeparttablex
that \item[xxx]
actually will generate a reference. So \label{tn:2}
will now pick the reference instead generated by the last command which has generated one. But there isn't any, so the output is simply empty. Adding a \section
demonstrates this:
\documentclass[letterpaper]{article}
\usepackage[referable]{threeparttablex}
\usepackage{enumitem}
\renewlist{tablenotes}{enumerate}{1}
\begin{document}
\section{Test} % <= This line added
\begin{table}[ht]
\centering
\begin{threeparttable}
\begin{tabular}{|l|c|c|}
\hline
A & 1 & 2 \tnote{1} \\
\hline
B & 2 & 1 \\
\hline
C & 3 \tnotex{tn:2} & 3 \\
\hline
Line & producing & space. \\
\hline
\end{tabular}
\begin{tablenotes}
\item[1] This is the first note.
\item[2] \label{tn:2} This is the hyperlinked note.
\end{tablenotes}
\end{threeparttable}
\caption{A table caption.}
\end{table}
\end{document}
Now \tnotex{tn:2}
will produce a 1
(instead of the expected 2
) because \label{tn:2}
(still) does not point to the \item[2]
but to the (first) section instead.
But why does the example document offered by cfr gives the correct output? Because it uses \item
without optional argument, and as we know from above this will always produce proper references.
Now the last part of the story: What does the caption
package has to do with all of this?
Well, the caption
package has a feature which detects \label
without proper reference within figure
, table
, threeparttable
etc. And since this is exactly the problem here this feature will strike.
BUT: I confess that the content of the warning message offered by the caption
package is misleading here. I choose the text "\label without proper \caption" since a \label
without a leading \caption
is usually the problem here. I will change it to the more technically correct text "\label without a proper reference" in the next version.
[1] This is a documented feature of the threeparttablex
package: "By using the package option »referable« we will change a few threeparttable internals such that (a) The manually specified note markers issued by \item[...] is referable, and ..." (Taken from the threeparttablex
documentation, as of May 22, 2014)
\item[1]
.