我正在使用 Node 和 LaTeX 创建一个动态 PDF 创建器,并使用 pdflatex(pdfTeX 3.14159265-2.6-1.40.20)进行编译。
问题是我试图创建一个动态大小的表格,当它溢出页脚时可以 \pagebreak,我尝试使用很多表格包,如longtable
,,,等等,但我总是遇到麻烦longtabu
,tabularx
它向我显示以下消息:
! Misplaced \noalign.
\pagebreak ->\noalign
{\ifnum `}=0\fi \@testopt {\LT@no@pgbk -}4
l.702 \end{xltabular}
例子
\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}
最奇怪的是:我的 .tex 确实生成了一个 PDF 文件,但它也因错误而崩溃
编辑1:提供我的代码的更好的例子,这样我们就可以找出问题
答案1
Missing character: There is no l in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no f in font nullfont!
Missing character: There is no t in font nullfont!
LaTeX Warning: Reference `LastPage' on page 1 undefined on input line 125.
! Misplaced \noalign.
\pagebreak ->\noalign
{\ifnum `}=0\fi \@testopt {\LT@no@pgbk -}4
l.125 \end{xltabular}
%
字符警告是由于之前缺少逗号left
,主要错误是显示 longtable 的\\
定义发生在表格之外,tcolorbox 代码必须在页脚的任何地方运行它,因为她实际上不能成为信息框内的分页符,我只是在本地定义\pagebreak
不执行任何操作。
\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){% why the weird non standard () syntax???
\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}%%%
\renewcommand\pagebreak[1][]{}%%%
\infobox(\textit{RANDOM})%%%
}
\newpage
\infobox(\textbf{TEXT 1TEXT 2 (TEXT 3)})
\begin{center}
TEXT EXPLAINING WHAT THE TABLE MEANS.
\end{center}
\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}