0

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.

2
  • 1
    You forgot to terminate (by \\ ) 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 ...
    – Zarko
    Commented Jul 21 at 7:50
  • I would be happy to have Table x.x continued on next page instead. Again, I don't know how to configure the caption within the multicolumn for the current Continued code.
    – Michelle
    Commented Jul 21 at 8:51

2 Answers 2

1

The error should be clear: the error

! Misplaced \noalign.
\addlinespace ->\noalign
                         {\ifnum 0=`}\fi \@ifnextchar [{\@addspace }{\@addsp...

means that you didn't terminate a row. You need to add \\ before the offending \addlinespace, in this case after \insertTableNotes.

I also made some adjustments in package loading (cleveref should be last and hyperref just before it). With caption and \captionsetup we get correct spacing for the caption.

\documentclass[12pt]{article}
\usepackage{csquotes}
\usepackage{longtable, booktabs, caption}
\usepackage[table, dvipsnames]{xcolor}
\usepackage[flushleft]{threeparttable}
\usepackage[online]{threeparttablex}
\usepackage{multirow}
%\usepackage{pgfplotstable} % not needed for the example
\usepackage[colorlinks]{hyperref}
\usepackage[noabbrev,nameinlink]{cleveref}

\definecolor{LightGray}{gray}{0.9}

\captionsetup[table]{position=bottom}

\begin{document}

My table is \Cref{tab:OriginalSP}.

\begin{ThreePartTable}
  \begin{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}

output

I typeset this with TeX Live 2023. For an updated TL 2024, see cleveref not working for label after caption in longtable

1
  • This worked. TexStudio is showing me that the \\ after insert TableNotes is in orange, which usually indicates a mistake with the code. I had been avoiding \\ in places where it was orange. But it compiles perfectly.
    – Michelle
    Commented Jul 21 at 22:49
1

How to remove errors in your code example I already mentioned in my comment.

Sorry, I do not entirely understand your comments, so below is MWE (which instead of longtable, threeparttablex and threeparttable use tabularray package), which -- if I correctly understood your comment -- produce what you after:

enter image description here

\documentclass[12pt]{article}
\usepackage{geometry}
\usepackage{csquotes}    

\usepackage[dvipsnames]{xcolor}  
\definecolor{LightGray}{gray}{0.9}
\usepackage{tabularray}    
\UseTblrLibrary{booktabs}

\usepackage[colorlinks]{hyperref}
\usepackage[noabbrev,nameinlink]{cleveref} 


\begin{document}

My table is \Cref{tab:OriginalSP}.

\begin{longtblr}[
caption = {There is a glossary call in here.},
  label = {tab:OriginalSP},
note{a} = {Blah.},
note{b} = {Blah.},
note{c} = {Blah.},
note{d} = {Blah.},
note{e} = {Blah.},
note{f} = {Blah.},
note{g} = {Blah \enquote*{Blah} blah \enquote*{blah}. Blah \enquote*{Blah}.}
                ]{width = 0.75\textwidth,
                  colspec = { Q[l,m] *{2}{X[l,m]} },
                  row{4-15, 18-22, 30, 32-33, 35-46, 48, 50, 54, 58} = {bg=LightGray},
                  rowsep = 0.5pt,
                  rowhead = 1}  
    \toprule
Variable    &   Type            &   Values              \\
    \midrule 
\SetCell[r=2]{} Blahs1\TblrNote{a}
            &   \SetCell[r=2]{} Blahs2
                                &   Blahs3              \\
            &                   &   Blahs4              \\
%
\SetCell[r=12]{}    AG\TblrNote{b}
            &   \SetCell[r=12]{}    Ordered factor
            &                   &   Blaha4              \\  % 4          
            &                   &   Blaha9              \\
            &                   &   Blaha14             \\
            &                   &   Blaha17             \\
            &                   &   Blaha24             \\
            &                   &   BlahaBlaha34        \\  % 10
            &                   &   BlahaBlaha44        \\
            &                   &   BlahaBlaha54        \\
            &                   &   BlahaBlaha64        \\
            &                   &   BlahaBlaha74        \\
            &                   &   BlahaBlaha84        \\  
            &                   &   Blaha104            \\  % 16
%
\SetCell[r=2]{} PS\TblrNote{c} 
            &   \SetCell[r=2]{}    Character
                                &   NP                  \\  
            &                   &   P                   \\
%
\SetCell[r=5]{} UR\TblrNote{a}
            &   \SetCell[r=5]{}    Factor 
                                &   One blah            \\  % 19
            &                   &   Two blah            \\
            &                   &   Three blah          \\
            &                   &   Four blah           \\   
            &                   &   Five blah           \\  % 23

\SetCell[r=7]{} HW\TblrNote{a}  &   \SetCell[r=7]{} Ordered factor 
                                &   NH                  \\  *
            &                   &   H9                  \\  *
            &                   &   H19                 \\  *
            &                   &   H29                 \\  *
            &                   &   H39                 \\  *
            &                   &   H49                 \\  *
            &                   &   H 50 Plus           \\  *
%
ID\TblrNote{b} 
            & Numeric           & Range: blah to blah   \\  %31
%
A           & Numeric           & Range: blah to blah   \\
\SetCell[r=2]{} ES 
            &   \SetCell[r=2]{} Ordered factor
                                &   N                   \\  % 33
            &                   &   Y                   \\  % 34
HID\TblrNote{c} 
            & Numeric           & Range blah to blah    \\
%
\SetCell[r=12]{} Type
            &   \SetCell[r=12]{} Character
                                &   A                   \\  % 36
            &                   &   C                   \\
            &                   &   OS no blah          \\
            &                   &   OS with blah        \\
            &                   &   OS without blah     \\
            &                   &   Other               \\
            &                   &   Other with blah     \\
            &                   &   RH resident         \\
            &                   &   SS no blah          \\
            &                   &   SS with blah        \\
            &                   &   SF                  \\   
            &                   &   SM                  \\  % 47
SID\TblrNote{d} 
            & Numeric           &   Range: \enquote*{blah} to \enquote*{blah} 
                                                        \\  *
IC          & Character         &   Range: \enquote*{blah} to \enquote*{blah} 
                                                        \\  *   %49
IN          & Character         &   Range: \enquote*{blah} to \enquote*{blah} 
                                                        \\  *   
C\TblrNote{e} 
            & Character         &   Range: \enquote*{blah} to \enquote*{blah} 
                                                        \\ *    % 51
SetCell[r=3]{} EI   
            &   SetCell[r=3]{} Character
                                &   C                   \\ *    
            &                   &   N                   \\
            &                   &   S                   \\
EP\TblrNote{f} Character 
            &   Range: \enquote*{blah} to \enquote*{blah} \\ % 55
\SetCell[r=3]{} RI
            &   \SetCell[r=3]{} Character
                                &   N                   \\
            &                   &   R                   \\
            &                   &   S                   \\
RH\TblrNote{g} 
            & Character         &   Range: \enquote*{blah} to \enquote*{blah}
                                                        \\  % 59
    \bottomrule
\end{longtblr}

More text is here.

\end{document}
1
  • I have tried that package in the past, and can't generalise from worked examples such as yours, to other tables I need. I agree that it is a good solution, just not for me.
    – Michelle
    Commented Jul 22 at 1:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .