0

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.

Michelle
  • 519
  • 1
  • 4
  • 15
  • Please (i) make your document example shorter (remove all stuff from preamble, which is not related to your table, (ii) remove termination after \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
  • I have included the detail in the preamble just in case it was something in the preamble that was causing the problem. Problem continues after the terminations for addlinespace removed. – Michelle Dec 03 '23 at 07:50
  • Why you need to put some command before \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
  • It's doing the line if I put it between \end{longtblr} and \end{landscape}, but two problems occur: 1. I get a "Running in backwards compatibility mode" warning. 2. the bottom line is printed below the table notes and table caption, instead of under the last row and above the table notes/caption. Getting very dispirited about this package. – Michelle Dec 03 '23 at 08:12
  • Now I suspect that you may use `remarm7 options, which you should write in table preamble. For example, see https://tex.stackexchange.com/q/616003/ – Zarko Dec 03 '23 at 08:16
  • I commented out all the \DefTblrTemplate and \UseTblrTemplate lines and re-compiled. I still cannot get \bottom rule to work under the last entry. It will work between entries, which isn't helpful though. Thus, even using the default (I think) tabularray template, it isn't working. Could something in my preamble be interfering with it? – Michelle Dec 03 '23 at 08:50
  • Make a (much) shorter example. If you don't know if e.g. a package is relevant then test it: comment the package and look if the issue is still there. Repeat with the next package. And make your example complete. We must be able to compile and reproduce your issue. – Ulrike Fischer Dec 03 '23 at 08:53
  • After banging my head for so many hours, I found out the fix. Literally, put \ after the last row of the table with \bottomrule on the following line. Tabularray seems very finicky about line returns. – Michelle Dec 03 '23 at 08:56

2 Answers2

1

Nobody asked you to remove packages in your dissertation. But if you ask for (free) help to debug a problem you shouldn't simply dump all your packages and so thousands of unrelated code lines in your questions. Even without much LaTeX skills you can reduce the preamble and built a shorter test document in quite a short time.

In your case as you have a problem with a longtblr you can (in an new test document!) test if you get the error also if you load only the package and the booktabs library and copy your tabular (you do). Then as you already know that you get the error by adding something at the end you can try to shorten the table a bit more by remove previous lines.

With this method it took me only a few minutes to get this:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}

\begin{longtblr}{colspec = {l l l l l l l l},} & & & & & & & Vaccinated\TblrNote{s} \ *

\bottomrule % <- causes an error \end{longtblr} \end{document}

and then you can ask a question and someone will tell you that tabularray seems not to like an empty line after a \\* (this looks like a bug to me) and that this compiles:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}

\begin{longtblr}{colspec = {l l l l l l l l},} & & & & & & & Vaccinated\TblrNote{s} \*
\bottomrule % \end{longtblr} \end{document}

Ulrike Fischer
  • 327,261
1

In general, tabularray is designed to actually simplify code for making custom tables, whereas you have created great deal of unnecessarily complicated code. I strongly recommend to read documentation. The manual is clear and easy to follow, although you might find the part related to longtblr a bit more difficult to grasp, at first. Regardless, you should still have much better understanding of how tabularray works.

For starters, you could separate definitions from the content. All those mergings can be set in table specification and then have a clean code in the part with context definition. Also, tabulararray lets you insert multiple lines in one cell. This needs to be guarded by curly brackets: {Aaaa\\Bbbb\\...\\Zzz}. These are just a couple of examples.

Below is much reduced code to render the table, which I believe meet your expectations

\documentclass{article}
\usepackage[
  a4paper,
  layout=a4paper,
  bindingoffset=2cm,
  left=2cm,
  right=2cm,
  head=2.5cm,
  bmargin=2cm,
]{geometry}
\usepackage{pdflscape}
\usepackage{tabularray}
\usepackage{kantlipsum}   % Dummy text

\UseTblrLibrary{booktabs,siunitx}

% define position of caption in tabularray so it sits under the table \DefTblrTemplate{firsthead,middlehead,lasthead}{default}{} \DefTblrTemplate{firstfoot,middlefoot}{default}{ \itshape(Cotinues on next page ...) } \DefTblrTemplate{lastfoot}{default}{ \UseTblrTemplate{note}{default} \UseTblrTemplate{caption}{default} } \DefTblrTemplate{note}{default}{ \MapTblrNotes{ \noindent\footnotesize \UseTblrTemplate{note-tag}{default} \UseTblrTemplate{note-sep}{default} \UseTblrTemplate{note-text}{default}\par } }

\begin{document} \kant[1]

\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} = {Follow-up period for detecting infected contacts.}, note{b} = {Number of households assumed to be the same as the number of index cases.}, note{s} = {Statistically significant.}, ]{ stretch = 0, colspec = {@{} *8{Q[l]} @{}}, rowhead = 2, % row{3-Z} = {rowsep=6pt}, row{3} = {abovesep=3pt}, row{Z} = {belowsep=3pt}, % cells = {font=\small}, cell{1}{1,2,3,7,8} = {r=2}{}, cell{1}{4} = {c=3}{c}, cell{1-Z}{8} = {}{m}, } \toprule Study & Country & Number of & Secondary attack rate & & & Analysis method & Demographics examined \ & & households & period\TblrNote{a} & households & contacts & & \ \midrule \cite{Julin1} & Norway & 65 & 14 days & 66% & 49.6% & 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} \ \cite{Stich1} & Germany & 405 & n.s. & n.s & 32.8% & 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} \ \cite{Derqui1} & UK & 279 & 28 days & n.s. & 36.7% & Chi-squared & {Age of contact\Sex of contact\Contact relationship to index case\Number in household\Household density\Vaccinated\TblrNote{s}} \ \bottomrule \end{longtblr} \end{landscape}

\kant[2] \end{document}

Celdor
  • 9,058