I have a wide table that needs to go across multiple pages in landscape mode. The format of my document is that the table caption goes underneath the table. This is causing me problems such as I'm not getting the "continued" message under the table, but I can live with that.
The problem I am facing now is that if I try to put any command between the last row of my table, and \end{longtblr}, it puts errors into my log, and the pdf fails to compile.
\documentclass{article}
\usepackage{csquotes} % must load BEFORE babel
\usepackage[english]{babel}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{amsfonts}
\usepackage[a4paper,layout=a4paper,
bindingoffset=2cm,left=2cm,right=2cm,
head=2.5cm, bmargin=2cm]{geometry} %get the page layout right
\usepackage{microtype} %better typesetting, affects justification and punctuation
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage{url} % typeset URL's reasonably
\usepackage[round]{natbib} % default bracket type is round
\usepackage{listings}
\usepackage{booktabs} %typeset tables better
\usepackage{multirow} %allow merge look across table rows
%\usepackage{placeins} %fix table floats!
\RequirePackage[l2tabu, orthodox]{nag}
\usepackage[table]{xcolor} % must be imported BEFORE tikz
\usepackage{tikz} %write flowcharts etc
\usetikzlibrary{arrows, shapes, chains, fit, backgrounds, calc, decorations.pathreplacing, matrix, calligraphy, positioning}
\usepackage{hyperref}
\usepackage[flushleft]{threeparttable}
\usepackage[inline, shortlabels]{enumitem}
\usepackage{tikzlings}
\usepackage{array}
%\usepackage{rotating} % replaced with pdflscape, check for \begin{sidewaysfigure}
\usepackage{subcaption}
\usepackage{cleveref} %sensible cross-referencing ***MUST BE PLACED AFTER HYPERREF PACKAGE IF THAT PACKAGE IS USED***
\usepackage{varwidth}
\usepackage{pdflscape}
\usepackage{mfirstuc}
\usepackage{afterpage}
\usepackage{pgfplotstable}
\usepackage{soul} % needed for strikethrough
\usepackage{siunitx} % for SI units so they don't format badly
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
% try and get a lower case first letter for the section hyperlinks working
\newcommand{\lnameref}[1]{%
\bgroup
\let\nmu\MakeLowercase
\nameref{#1}\egroup}
\newcommand{\fnameref}[1]{%
\bgroup
\def\nmu{\let\nmu\MakeLowercase}%
\nameref{#1}\egroup}
\newcommand{\nmu}{}
% define position of caption in tabularray so it sits under the table
\DefTblrTemplate{firsthead,middlehead,lasthead}{default}{}
\DefTblrTemplate{firstfoot,middlefoot}{default}{} % <---
\DefTblrTemplate{lastfoot}{default}% % <---
{
\UseTblrTemplate{note}{default}
\UseTblrTemplate{caption}{default}
}
\newcommand{\vp}[2]{%
\begin{varwidth}{#1}\raggedright #2\end{varwidth}%
}
% Uncomment the next line if you want subsubsections to be numbered
\setcounter{secnumdepth}{3}
% Uncomment the next line if you want subsubsections to be appear in the table of contents
\setcounter{tocdepth}{3}
% set up table alignment
\newcolumntype{L}[1]{>{\raggedright\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
% greyscale for table rows
\definecolor{LightGray}{gray}{0.9}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vulputate velit vitae risus euismod rutrum eu eget tortor. Fusce in ex eu ante sagittis interdum. Phasellus bibendum hendrerit massa elementum tincidunt. Fusce cursus odio sit amet varius aliquam. Suspendisse imperdiet posuere orci congue congue. Aliquam leo quam, sodales ut sapien vel, viverra convallis felis.
\afterpage{%
\begin{landscape}
\begin{longtblr}[
caption = {Demographics associated with becoming an infected household contact, SARS-CoV-A, western countries. Only demographics included in the synthetic population shown.},
label = {tab:SARS},
note{a} = {\footnotesize Follow-up period for detecting infected contacts.},
note{b} = {\footnotesize Number of households assumed to be the same as the number of index cases.},
note{s} = {\footnotesize Statistically significant.},
]{
colspec = {l l l l l l l l},
rowhead = 2,
column{7}={5cm},
stretch=0,
row{1-Z} = {font=\small},
}
\toprule
\SetCell[r=2]{c}Study
& \SetCell[r=2]{c}Country
& Number of
& \SetCell[c=3]{c}Secondary attack rate
& & & \SetCell[r=2]{c}Analysis method
& \SetCell[r=2]{c}Demographics examined \
& & households & period\TblrNote{a} & households & contacts & & \
\midrule
\SetCell[r=6]{l}\cite{Julin1} & \SetCell[r=6]{l}Norway & \SetCell[r=6]{l}65 & \SetCell[r=6]{l}14 days & \SetCell[r=6]{l}66% & \SetCell[r=6]{l}49.6% & \SetCell[r=6]{l}Mixed-effect logistic regression & Age of index case\TblrNote{s} \
& & & & & & & Sex of index case \
& & & & & & & Age of contact \
& & & & & & & Sex of contact \
& & & & & & & Number in household\TblrNote{s} \
& & & & & & & Number of bathrooms \
\addlinespace[.3em] \\
\SetCell[r=5]{l}\cite{Stich1}&\SetCell[r=5]{l}Germany & \SetCell[r=5]{l}405 & \SetCell[r=5]{l}n.s. & \SetCell[r=5]{l}n.s & \SetCell[r=5]{l}32.8% & \SetCell[r=5]{l}Multivariable linear mixed-effect logistic regression &
Age of index case\TblrNote{s} \
& & & & & & & Sex of index case \
& & & & & & &Age of contact\TblrNote{s} \
& & & & & & & Sex of contact \
& & & & & & & Number in household \
\addlinespace[.3em] \\
\SetCell[r=5]{l}\cite{Telle1} & \SetCell[r=5]{l}Norway & \SetCell[r=5]{l}7548\TblrNote{b} & \SetCell[r=5]{l}7 days & \SetCell[r=5]{l}n.s & \SetCell[r=5]{l}21% & \SetCell[r=5]{l}Wilson score interval & Age of index case\TblrNote{s} \
& & & & & & & Sex of index case \
& & & & & & & Age of contact\TblrNote{s} \
& & & & & & & Sex of contact\TblrNote{s} \
& & & & & & & Number in household\TblrNote{s} \
\addlinespace[.3em] \\
\SetCell[r=6]{l}\cite{Cerami1} & \SetCell[r=6]{l}USA & \SetCell[r=6]{l}91 & \SetCell[r=6]{l}28 days & \SetCell[r=6]{l}69% & \SetCell[r=6]{l}32% & \SetCell[r=6]{l}Chi-squared/Mann-Whitney U test & Age of index case \
& & & & & & & Sex of index case \
& & & & & & & Age of contact \
& & & & & & & Sex of contact \
& & & & & & & Contact relationship to index case \
& & & & & & & Household density \
\addlinespace[.3em] \
\SetCell[r=4]{l}\cite{Kolodziej1} & \SetCell[r=4]{l}Netherlands & \SetCell[r=4]{l}85 & \SetCell[r=4]{l}42 days & \SetCell[r=4]{l}88.2% & \SetCell[r=4]{l}64.3% & \SetCell[r=4]{l}Logistic regression & Age of index case \
& & & & & & & Sex of index case \
& & & & & & & Age of contact \
& & & & & & & Sex of contact \
\addlinespace[.3em] \\
\SetCell[r=6]{l}\cite{Derqui1} & \SetCell[r=6]{l}UK & \SetCell[r=6]{l}279 & \SetCell[r=6]{l}28 days & \SetCell[r=6]{l}n.s. & \SetCell[r=6]{l}36.7% & \SetCell[r=6]{l}Chi-squared & Age of contact \*
& & & & & & & Sex of contact \*
& & & & & & & Contact relationship to index case \*
& & & & & & & Number in household \*
& & & & & & & Household density \*
& & & & & & & Vaccinated\TblrNote{s} \ *
\bottomrule % <- causes an error
%\toprule <- also causes an error
% anything I insert in here causes an error
% \midrule
% \addlinespace[.3em]
\end{longtblr}
\end{landscape}
\clearpage %% <------- important
} \end{document}
I have tried the \bottomrule etc both with an end \\ and without an \\and nothing works. I thought that maybe the problem was me doing a split of one of my referenced studies, so I added in the *to stop the study information being split across two pages. That wasn't the problem.
The commands all work at the top of the table, under the heading rows, between the table rows, but not at the end of the table.
What do I need to do to fix the table? This is part of my dissertation, hence the massive number of packages loaded at the start of the document.
Edit: I have included my entire preamble as it is part of my document. I can't remove the packages from my preamble otherwise other parts of my dissertation will fail. A "fix" that requires me to remove everything in my preamble unrelated to this specific table is not a fix.
\addlinespace[.3em], (iii) it seems that your document example (after cleanup all clutter from it) doesn't reproduce reported problem,. – Zarko Dec 03 '23 at 07:25\end{longtblr}? It is considered as content of cell and If it is not complain to package syntax, it will throw error. Insert it after\end{tabular}. – Zarko Dec 03 '23 at 08:03