I cannot work out how to put a table caption and label at the bottom of a multiple page table created with ThreePartNotes
and longtable
. The format I must use for my tables is for the caption to be underneath. What I have ended up with:
\documentclass[12pt]{article}
\usepackage{csquotes}
\usepackage{longtable, booktabs}
\usepackage[colorlinks]{hyperref}
\usepackage[table, dvipsnames]{xcolor} % must be imported BEFORE tikz
\usepackage[noabbrev,nameinlink]{cleveref}
\usepackage[flushleft]{threeparttable}
\usepackage[online]{threeparttablex}
\usepackage{multirow}
\usepackage{pgfplotstable}
\definecolor{LightGray}{gray}{0.9}
\begin{document}
My table is \Cref{tab:OriginalSP}.
\begin{ThreePartTable}
\begin{TableNotes} %%% This should come before longtable and it is not tablenotes but TableNotes
\footnotesize
\item[a] Blah.
\item[b] Blah.
\item[c] Blah.
\item[d] Blah.
\item[e] Blah.
\item[f] Blah.
\item[g] Blah \enquote*{Blah} blah \enquote*{blah}. Blah \enquote*{Blah}.
\end{TableNotes}
\begin{longtable}{l l l}
\toprule
Variable & Type & Values \\
\midrule
\endhead
\bottomrule
\multicolumn{3}{l}{{\emph{Continued on next page}}} \\
\endfoot
\bottomrule
\insertTableNotes
\addlinespace
\caption{There is a glossary call in here.\label{tab:OriginalSP}}
\endlastfoot
\multirow{2}{*}{Blahs1\tnote{a}} & \multirow{2}{*}{Blahs2} & Blahs3 \\
& & Blahs4 \\
\rowcolor{LightGray}& & Blaha4 \\
\rowcolor{LightGray}& & Blaha9 \\
\rowcolor{LightGray} & & Blaha14\\
\rowcolor{LightGray} & & Blaha17 \\
\rowcolor{LightGray} & & Blaha24 \\
\rowcolor{LightGray} & & Blaha34\\
\rowcolor{LightGray} & & Blaha44\\
\rowcolor{LightGray}& & Blaha54 \\
\rowcolor{LightGray}& & Blaha64 \\
\rowcolor{LightGray}& & Blaha74 \\
\rowcolor{LightGray}& & Blaha84 \\
\rowcolor{LightGray}\multirow{-12}{*}{AG\tnote{a}} & \multirow{-12}{*}{Ordered factor} & Blaha104 \\
\multirow{2}{*}{PS\tnote{a}} & \multirow{2}{*}{Character} & NP \\
& & P \\
\rowcolor{LightGray}& & One blah\\
\rowcolor{LightGray}& & Two blah \\
\rowcolor{LightGray}& & Three blah \\
\rowcolor{LightGray}& & Four blah \\
\rowcolor{LightGray}\multirow{-5}{*}{UR\tnote{a}} & \multirow{-5}{*}{Factor} & Five blah \\
\multirow{7}{*}{HW\tnote{a}} & \multirow{7}{*}{Ordered factor} & NH \\
& & H9 \\
& & H19 \\
& & H29 \\
& & H39 \\
& & H49 \\
& & H 50 Plus \\
\rowcolor{LightGray}ID\tnote{b} & Numeric & Range: blah to blah\\
A & Numeric & Range: blah to blah \\
\rowcolor{LightGray} & & N \\
\rowcolor{LightGray}\multirow{-2}{*}{ES}& \multirow{-2}{*}{Ordered factor} & Y \\
HID\tnote{c} & Numeric & Range blah to blah \\
\rowcolor{LightGray}& & A \\
\rowcolor{LightGray}& & C \\
\rowcolor{LightGray}& & OS no blah \\
\rowcolor{LightGray}& & OS with blah \\
\rowcolor{LightGray}& & OS without blah \\
\rowcolor{LightGray}& & Other \\
\rowcolor{LightGray}& & Other with blah \\
\rowcolor{LightGray}& & RH resident \\
\rowcolor{LightGray}& & SS no blah \\
\rowcolor{LightGray}& & SS with blah \\
\rowcolor{LightGray}& & SF \\
\rowcolor{LightGray}\multirow{-12}{*}{Type} & \multirow{-12}{*}{Character} & SM \\
SID\tnote{d} & Numeric & Range: \enquote*{blah} to \enquote*{blah} \\
\rowcolor{LightGray}IC & Character & Range: \enquote*{blah} to \enquote*{blah} \\
IN & Character & Range: \enquote*{blah} to \enquote*{blah} \\
\rowcolor{LightGray}C\tnote{e} & Character & Range: \enquote*{blah} to \enquote*{blah} \\
\multirow{3}{*}{EI} & \multirow{3}{*}{Character} & C \\
& & N \\
& & S \\
\rowcolor{LightGray}EP\tnote{f} & Character & Range: \enquote*{blah} to \enquote*{blah} \\
\multirow{3}{*}{RI} & \multirow{3}{*}{Character} & N \\
& & R \\
& & S \\
\rowcolor{LightGray}RH\tnote{g} & Character & Range: \enquote*{blah} to \enquote*{blah} \\
\end{longtable}
\end{ThreePartTable}
More text is here.
\end{document}
I am getting noalign errors.
This answer from 2014 suggested that I needed to do a \\
after the caption and label command, using the format:
\caption{Captions should appear on top of tables}\label{tbl:table}\\
I still got the noalign problem.
This answer from 2018 also had the \\
solution. I tried it with and without the \label
and it didn't work. When I use \\
they show as an error in the latex code (orange highlight), even before I try to compile to PDF.
I thought I was following the Longtable
manual (see p.4 of that) for captions, I can't see where I am going wrong.
If I comment out the \addlinespace
and the caption/label lines it compiles to PDF.
\\
) two lines in table headers: \insertTableNotes and \caption. After terminate those lines properly (by addiding\\
at the end of lines), compilation works fine. I wonder why you like to have caption at the end of table at its bottom? That is not good praxis ...