I'm creating a dynamic PDF creator using Node and LaTeX, compiling with pdflatex (pdfTeX 3.14159265-2.6-1.40.20).
The problem is that I am attempting to create a dynamic sized table, that can \pagebreak when it overflows the footer, I tried using a lot of table packages such as longtable
, longtabu
, tabularx
, etc.. but I always run into a trouble where it shows me the following message:
! Misplaced \noalign.
\pagebreak ->\noalign
{\ifnum `}=0\fi \@testopt {\LT@no@pgbk -}4
l.702 \end{xltabular}
Example
\documentclass[a4paper,
listof=totoc,
]{scrreprt}
\usepackage[table]{xcolor}
\usepackage[sfdefault]{roboto}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\geometry{margin=1.5cm, top=3cm, headsep=0.5cm, footskip=0.8cm}
\usepackage{graphicx}
\usepackage{lastpage}
% KOMA-Script package for header and footer
\usepackage[
manualmark,
]{scrlayer-scrpage}
\usepackage{tcolorbox}
\usepackage{xltabular}
\usepackage{tikz}
\setlength{\textheight}{0.95\textheight}
\setlength\extrarowheight{0pt}
\arrayrulecolor[HTML]{CECECE}
% header and footer
\clearpairofpagestyles
\ihead{\raisebox{0\height}[0pt][0pt]{\includegraphics[width=4.5cm]{example-image}}}
\ohead{\raisebox{0\height}[0pt][0pt]{\includegraphics[width=5cm]{example-image}}}
\setlength{\parindent}{0em}
\definecolor{primary-blue}{HTML}{00A2D7}
\definecolor{ndvi-green}{HTML}{38761d}
\definecolor{ndvi-orange}{HTML}{e69138}
\definecolor{table-header}{HTML}{83D361}
\def\infobox(#1){%
\tcbset{
frame code={}
left=0pt,
right=0pt,
top=0pt,
bottom=0pt,
colback=primary-blue,
colframe=white,
colupper=white,
width=\dimexpr\textwidth\relax,
enlarge left by=0mm,
boxsep=5pt,
arc=0pt,outer arc=0pt,
halign = center
}
\begin{tcolorbox}
\normalfont\textbf{\large #1}
\end{tcolorbox}
}
\begin{document}
\cfoot{
\thepage\ de \pageref{LastPage}
\infobox(\textit{RANDOM})
}
\newpage
\infobox(\textbf{TEXT 1\\TEXT 2 (TEXT 3)})
\centering{
TEXT EXPLAINING WHAT THE TABLE MEANS.
}
\begin{xltabular}{0.7\linewidth}{|c|c|c|}
\hline
\rowcolor{table-header}
{\cellcolor{table-header}{\color[HTML]{FFFFFF} \textbf{COL 1}}} & {\color[HTML]{FFFFFF} \textbf{COL 2}} & {\color[HTML]{FFFFFF} \textbf{COL 3}}
\\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
DATA 1 & DATA 2 & DATA 3 \\ \hline
\end{xltabular}%
\end{document}
The weirdest thing is: my .tex DOES GENERATE a PDF file, but it also crashes with the Misplaced error
EDIT 1: providing a better example of my code so we can figure out the problem
Best Answer
The character warnings ar due to a missing comma before
left
, the main error is showing longtable's\\
defiiion happening ouside a table, the tcolorbox code mus b running it spmewhere in the page foot, as her can't actually be a page break inside th infobox I just locally defind\pagebreak
to do nothing.