# Labeling threeparttable footnotes

I want to label footnotes using the threeparttable package, but it does not seem to be able to assign a label without proper caption. In fact if I disable the \caption package it works. But I need the package for the font size.

\documentclass[12pt]{report}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{threeparttable}
\usepackage[font=small, labelfont=bf]{caption}

\usepackage{tikz}
\usetikzlibrary{matrix, backgrounds}
\tikzset{
table/.style={
matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={
rectangle,
align=center,
text width=10em,
},
nodes in empty cells,
row 1/.style={nodes={fill=black, text=white, font=\bfseries}, text height=0.8em},
}
}

\begin{document}

\begin{table}
\centering
\caption{Glossary: with \texttt{TikZ} drawing cells on background layer}
\label{tabA1}
\begin{threeparttable}
\begin{tikzpicture}
\matrix[table, ampersand replacement=\&] (TabA1)
{
A1 \& A2\stepcounter{footnote}\tnote{\thefootnote} \& A3 \\
B1\footnotemark{} \& B2 \& B3\footnotemark{} \\
C1 \& C2\textsuperscript{\ref{note1}} \& C3                                  \\
};

%\begin{scope}[on background layer]
%\foreach \i in {1,2,3}
%\draw[fill=black!10] ([xshift=\pgflinewidth]TabA1-1-\i.south west) rectangle ([xshift=-\pgflinewidth]TabA1-2-\i.south east);
%\end{scope}

\end{tikzpicture}
\begin{tablenotes}\footnotesize
\stepcounter{footnote}
\item[\thefootnote]{\label{note1} This is broken.}
\stepcounter{footnote}
\stepcounter{footnote}
\end{tablenotes}
\end{threeparttable}
\end{table}
\stepcounter{footnote}\footnotetext{This seems to be ok}
\stepcounter{footnote}\footnotetext{This seems to be ok too}

\end{document}

• What you want is not very clear to me. Do you mean you want table notes to be referable? It seems you don't use table notes in a correct way? Furthermore, to cross-reference table notes, you have to use the threeparttablex package, which has a slightly different syntax w.r.t. threeparttable. – Bernard Sep 12 '18 at 23:53
• The superscript of C2 should be 1, the same as for A2. The corresponding footnote for A2 is labeled by note1. It's inner label also seems to be 1 which is then referenced in the table at C2 to show the same superscript as A2, since when I disable the caption package everything works, so I guess I'm not using it wrong. But it stops working as soon as I use the caption package. – Diger Sep 13 '18 at 0:00
• Normally, the table notes are numbered by hand, independently of the footnote counter, with commands such as \tnote{1}, &c. I insist that these table notes can be cross-referenced with the threeparttablex package, and you should take look at its documentation. – Bernard Sep 13 '18 at 0:13
• I found mirrors.rit.edu/CTAN/macros/latex/contrib/threeparttablex/…, but I'm not sure where precisely the cross-referencing I want takes place. Is it possible to change the caption font without the caption package? – Diger Sep 13 '18 at 0:20
• I've posted a solution. However, I wonder why you need a hammersledge like tikzpicture just to colour the background of a row? – Bernard Sep 13 '18 at 1:00

Here is how to do it with threeparttablex:

\documentclass[12pt]{report}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage[referable]{threeparttablex}
\usepackage[font=small, labelfont=bf]{caption}

\usepackage{tikz}
\usetikzlibrary{matrix, backgrounds}
\tikzset{
table/.style={
matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={
rectangle,
align=center,
text width=10em,
},
nodes in empty cells,
row 1/.style={nodes={fill=black, text=white, font=\bfseries}, text height=0.8em},
}
}

\begin{document}

\begin{ThreePartTable}
\setTableNoteFont{\footnotesize}
\renewcommand\TPTminimum{\textwidth}
\begin{TableNotes}\footnotesize
\item[1] \label{note1} This is not broken.
\item[2]\label{note2} This seems to be ok.
\item[3]\label{note3} This seems to be ok too.
\end{TableNotes}
\begin{longtable}{p{\linewidth}}
\caption{Glossary: with \texttt{TikZ} drawing cells on background layer}
\label{tabA1}
\endfoot
\insertTableNotes \\
\endlastfoot
{\begin{tikzpicture}
\matrix[table, ampersand replacement=\&] (TabA1)
{
A1 \& A2\tnotex{note1} \& A3 \\
B1\tnotex{note2} \& B2 \& B3\tnotex{note3} \\
C1 \& C2\tnotex{note1} \& C3 \\
};
\end{tikzpicture}}
\end{longtable}
\end{ThreePartTable}

\end{document}


• Thanks. I will try tomorrow. However, I wonder why you need a hammersledge like tikzpicture just to colour the background of a row?: lol xD I actually don't know. At some point I wanted to do tables for a report were I needed color circles positioned somewhere (see my history) and I continued to use tikz for all other tables, because I like the vast options one has. Actually why are you using longtable instead of table? – Diger Sep 13 '18 at 1:11
• Hm What does {p{\linewidth}} do? Also: \endfirsthead \endfoot \insertTableNotes \\ \endlastfoot is before the tikz table, so you insert the table notes before the actual table, but in the result you posted it is underneath the tikz table. How is that? – Diger Sep 13 '18 at 1:18
• p{\linewidth} specifies the column will be typed in paragraph mode, wwith a the same width as the current \linewidth. It's not really necessary – I just tested it for the table notes, and \begin{longtable}{c} is simpler and just as fine. As to \endfirsthead, \endhead, \endfoot, \endlastfoot, they're used by longtable to describe what should appear at the beginning of the table (usually a caption, and possibly column heads usually, at the beginning of the next pages (repeated column heads for instance), at the bottom of pages (e.g. the message ‘to be continued’) and of the table. – Bernard Sep 13 '18 at 8:21
• These declarative sections are to be used just after \begin{longtable}, just as \begin{TableNotes} … \end{TableNotes}  has to be used just after \bein{ThreePartTable}. See the documentation of the packages for more details. – Bernard Sep 13 '18 at 8:28
• Before? In this answer it is put below the actual table and not directly after \begin{ThreePartTable}: tex.stackexchange.com/questions/211898/… So if I use table instead of longtable I do not need \endfirsthead, \endhead, \endfoot, \endlastfoot ? And why do you renew the command \textwidth as in \renewcommand\TPTminimum{\textwidth} ? – Diger Sep 13 '18 at 12:29