Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to have a big table (break across pages) with footnotes and a column with adjustable width. The MWE is the following.

\documentclass{scrartcl}

\usepackage{blindtext}

\usepackage{tabu,longtable}
\usepackage{threeparttable} % <-- the package below already loads it
\usepackage[referable]{threeparttablex}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{hyperref}

\usepackage{etoolbox}
\makeatletter
\chardef\TPT@@@asteriskcatcode=\catcode`*
\catcode`*=11
\expandafter\patchcmd\csname\string\threeparttable\endcsname
  {\TPT@hookin{tabular}}
  {\TPT@hookin{tabular}\TPT@hookin{tabu}}
  {}{}
\catcode`*=\TPT@@@asteriskcatcode
\makeatother

\begin{document}

\listoftables

\bigskip

\blindtext

\begin{ThreePartTable} 
\begin{TableNotes}
\footnotesize
\item[a] \label{tn:aa} Footnote in long table 1 (not linked).
\item[b] \label{tn:bb} Footnote in long table 2.
\source Some general note
\end{TableNotes}
\captionof{table}{A long table} % <-- caption inside longtabu within ThreePartTable does not produce correct hyperlink in LOT
\vspace{-\abovecaptionskip} % <-- removes the extra space (correct value?) 
\begin{longtabu}to\linewidth{llX} 
%\caption{A long table} \\ % <-- see above why it is commented
\toprule
Column 1 & & Column 2 \\
\midrule
\endfirsthead
\caption[]{A long table} \\
\toprule
Column 1 & & Column 2 \\
\midrule
\endhead
\cmidrule{3-3}
\multicolumn{3}{r}{\small\textit{continued}}
\endfoot
\bottomrule
\insertTableNotes\\
\endlastfoot
AAAA\tnotex*{tn:aa} & & BBBB \\
\newpage % <-- just testing break page
CCCC & & DDDD\tnotex{tn:bb} \\
\end{longtabu}
\end{ThreePartTable}

\blindtext

\end{document}

The problem is that \caption{} inside longtabu within ThreePartTable does not produce correct hyperlink in LOT. So I am an alternative solution using \captionof{}. But this not good because it does not have a consistence skip between caption and the firs line in the table. I would like to use \caption{}, does anyone know a solution?

share|improve this question
    
I searched inside the threeparttablex.sty and the problem seems to be related with the code: \renewcommand\tablenotes{% \let\TPTL@item=\item \renewcommand\item[1][]{\TPTL@item[##1]% \phantomsection\protected@edef\@currentlabel{##1}} \TPTL@generator\note{\TPTLnotename} \TPTL@generator\source{\TPTLsourcename} \TPTL@font\TPTL@tablenotes}. However if I remove the \phantomsection \caption{} seems to produce a correct link in LOT. But why? Is there any side drawbacks? –  cacamailg Sep 2 '12 at 13:16

1 Answer 1

up vote 1 down vote accepted

The below solution works. I defined a dummy counter, and used \refstepcounter{dummy} which mysteriously corrects the referencing system.

However I would like to have a more elegant solution: call \setdummy every time I use longtabu and not need manually adjust spaces with \vspace{-\baselineskip}.

\documentclass[captions=tableheading]{scrartcl}

\usepackage{blindtext}

\usepackage{hyperref}
\usepackage{tabu,longtable}
%\usepackage{threeparttable} % the package below already loads it
\usepackage[referable]{threeparttablex}
\usepackage{booktabs}
\usepackage{caption}

\usepackage{etoolbox} 
\makeatletter
\chardef\TPT@@@asteriskcatcode=\catcode`*
\catcode`*=11
\expandafter\patchcmd\csname\string\threeparttable\endcsname
  {\TPT@hookin{tabular}}
  {\TPT@hookin{tabular}\TPT@hookin{tabu}} % allow threeparttable with tabu
  {}{}
\catcode`*=\TPT@@@asteriskcatcode
\makeatother

\makeatletter
\newcounter{dummy}
\newcommand{\setdummy}{\refstepcounter{dummy}\addtocounter{dummy}{-1}}
\makeatother

\begin{document}

\listoftables

\bigskip

\blindtext

\begin{ThreePartTable}
\begin{TableNotes}
\footnotesize
\item[a] \label{tn:aa} A note
\item[b] Another note
\end{TableNotes}
\vspace{-\baselineskip} % correct the \\ in \setdummy
\begin{longtabu}{ll}
\setdummy \\
\caption{A long table}
\label{tab:test1} \\
\toprule
Column 1 & Column 2 \\
\endfirsthead
\toprule
Column 1 & Column 2 \\
\midrule
\endhead
\cmidrule{2-2}
\multicolumn{2}{r}{\textit{continued}}
\endfoot
\bottomrule
\insertTableNotes
\endlastfoot
% the contents of the table
A & B\tnotex{tn:aa} \\
%\newpage % just testing page break
C\tnote{b} & D \\
\end{longtabu}
\end{ThreePartTable}

\blindtext

\begin{table}[h]
\centering
\caption{A regular table}
\label{tab:test2}
\begin{tabu}{ll}
\toprule
Column 1 & Column 2 \\
\midrule
A & B \\
\midrule
C & D \\
\bottomrule
\end{tabu}
\end{table}

\blindtext

\end{document}
share|improve this answer
    
If you say \noalign{\phantomsection}\caption{...} instead of the "dummy" trick, it works the same without the need of adjusting the spacing. –  egreg Nov 2 '12 at 16:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.