我有一堆长度不一的长表,一个接一个地显示。有没有办法使用长表自动在每页的第一个表上运行宏或其他东西(无论它是全新的表,还是跨越多页的长表)?我想在每页的第一个表的标题中显示一张图片。
编辑:我将包含更多细节来解释和说明我想要实现的目标。我正在生成一个目录,其中有几组产品包含与它之前的组相同的图像。为了让这本书更小更简洁,我只显示第一组的图像,然后显示任何具有相同图像的表格的表格,直到图像发生变化或出现新页面。有时表格会跨越多页(这就是我使用 longtable 的原因)。如果该组是页面上的第一张,我想显示该组的图像,无论它是新表格还是跨页表格。我遇到的问题是,页面上的第一张表格是一个全新的表格(意味着不跨越上一页)。当发生这种情况时,它会跳过第一个表格,而是在下一个表格上显示图像(如果有的话)。我试图通过使用 AddEverypageHook 在每个新页面上设置为 true 的标志来解决这个问题。它似乎正在执行,但直到第二个表才生效。我将包括我正在使用的代码(如果其中有些内容不需要,我很抱歉,但至少你可以看到我在尝试做什么)。
\documentclass[8pt]{report}
\usepackage[final]{pdfpages}
\usepackage{fancyhdr}
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage{caption}
\usepackage{tocloft}
\usepackage[export]{adjustbox}
\usepackage{longtable}
\usepackage{hyperref}
\usepackage{helvet}
\usepackage{everypage}
\usepackage[space]{grffile}
\renewcommand{\familydefault}{\sfdefault}
\hypersetup{%
pdfborder = {0 0 0}
}
\setcounter{tocdepth}{5}
\pagestyle{fancy}
\renewcommand\footrule{\begin{minipage}{1\textwidth}
\hrule width \hsize height 2pt \kern 1mm \hrule width \hsize
\global\importanttrue
\end{minipage}\par}%
\lfoot{\today}
\rfoot{\thepage}
\cfoot{}
\rhead{}
\lhead{\leftmark}
\renewcommand {\headrulewidth}{0.4pt}
\renewcommand {\footrulewidth}{0.4pt}
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\captionsetup{labelsep=space,singlelinecheck=off,labelformat=empty,labelfont=bf}
%
\makeatletter
\setlength{\@fptop}{0pt}
\makeatother
%
\newif\ifimportant\importantfalse
\AddEverypageHook{
\global\importanttrue
}
\begin{document}\thispagestyle{empty}
\setlength\unitlength{1in}
\begin{titlepage}
\begin{center}
\includegraphics[width=.5\textwidth]{/var/www/html/hvac/css/catalog_logo.jpg}~\\[1cm]
\huge
{\fontsize{50}{60}\selectfont Product Catalog}\\
\vspace{.25in}
{\fontsize{30}{40}\selectfont DOUG PETERSON}\\
\vspace{.25in}
{\fontsize{20}{30}\selectfont \today}
\vfill
% Bottom of the page
{\large www.contractorshvacsupply.com}
\end{center}
\end{titlepage}
\setcounter{page}{2}
\tableofcontents
\includepdfset{pagecommand=\thispagestyle{fancy}}
\clearpage\phantomsection
\addcontentsline{toc}{chapter}{Residential Heating \& Cooling Equipment}
\markboth{Residential Heating \& Cooling Equipment}{}
\clearpage\phantomsection
\addcontentsline{toc}{section}{Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 92\% Legacy Single-Stage--912BA}
\global\importanttrue
Important is true
\begin{longtable}{|p{.625in}|p{1.5in}|p{2.75in}|p{.875in}|}
\caption{
\ifimportant
\protect\includegraphics[width=1.875in,height=1.875in,keepaspectratio,right]{Bry_90_GasFurnacePhoto_9.jpg}
\global\importantfalse
Important is false
\fi
Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 92\% Legacy Single-Stage--912BA}\\
\hline
Product\# & Model\# & Description & Price\\
\hline
\endfirsthead
\caption[]{
\protect\includegraphics[width=1.875in,height=1.875in,keepaspectratio,right]{Bry_90_GasFurnacePhoto_9.jpg}
\global\importantfalse
Important is false 2
Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 92\% Legacy Single-Stage--912BA}\\
\hline
Product\# & Model\# & Description & Price\\
\hline
\endhead
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\\hline
\end{longtable}
\addcontentsline{toc}{section}{Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 95\% Legacy Single-Stage--915SA}
\begin{longtable}{|p{.625in}|p{1.5in}|p{2.75in}|p{.875in}|}
\caption{
\ifimportant
\protect\includegraphics[width=1.875in,height=1.875in,keepaspectratio,right]{Bry_90_GasFurnacePhoto_9.jpg}
\global\importantfalse
Important is false
\fi
Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 95\% Legacy Single-Stage--915SA}\\
\hline
Product\# & Model\# & Description & Price\\
\hline
\endfirsthead
\caption[]{
\protect\includegraphics[width=1.875in,height=1.875in,keepaspectratio,right]{Bry_90_GasFurnacePhoto_9.jpg}
\global\importantfalse
Important is false 2
Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 95\% Legacy Single-Stage--915SA}\\
\hline
Product\# & Model\# & Description & Price\\
\hline
\endhead
328431 & 915SA30040S14 & 915SA30040S14 1STG 95 FURNACE & \$1183.96 ea\\\hline
404315 & 915SA36040S17 & 915SA36040S17 1STG 95 FURNACE & \$1194.63 ea\\\hline
330654 & 915SA42060S17 & 915SA42060S17 1STG 95 FURNACE & \$1224.64 ea\\\hline
330662 & 915SA42100S21 & 915SA42100S21 1STG 95 FURNACE & \$1355.81 ea\\\hline
330658 & 915SA48080S17 & 915SA48080S17 1STG 95 FURNACE & \$1314.06 ea\\\hline
330661 & 915SA60080S21 & 915SA60080S21 1STG 95 FURNACE & \$1328.39 ea\\\hline
330665 & 915SA60100S21 & 915SA60100S21 1STG 95 FURNACE & \$1372.00 ea\\\hline
330666 & 915SA60120S24 & 915SA60120S24 1STG 95 FURNACE & \$1411.96 ea\\\hline
330668 & 915SA60140S24 & 915SA60140S24 1STG 95 FURNACE & \$1444.31 ea\\\hline
\end{longtable}
\addcontentsline{toc}{section}{Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 95\% Preferred Single-Stage ECM--925SA}
\begin{longtable}{|p{.625in}|p{1.5in}|p{2.75in}|p{.875in}|}
\caption{
\ifimportant
\protect\includegraphics[width=1.875in,height=1.875in,keepaspectratio,right]{Bry_90_GasFurnacePhoto_9.jpg}
\global\importantfalse
Important is false
\fi
Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 95\% Preferred Single-Stage ECM--925SA}\\
\hline
Product\# & Model\# & Description & Price\\
\hline
\endfirsthead
\caption[]{
\protect\includegraphics[width=1.875in,height=1.875in,keepaspectratio,right]{Bry_90_GasFurnacePhoto_9.jpg}
\global\importantfalse
Important is false 2
Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 95\% Preferred Single-Stage ECM--925SA}\\
\hline
Product\# & Model\# & Description & Price\\
\hline
\endhead
210145 & 925SA30040E14 & 925SA30040E14 1STG ECM FURNACE & \$1233.76 ea\\\hline
210244 & 925SA42060E17 & 925SA42060E17 1STG ECM FURNACE & \$1315.63 ea\\\hline
210687 & 925SA48080E17 & 925SA48080E17 1STG ECM FURNACE & \$1446.71 ea\\\hline
210908 & 925SA48100E21 & 925SA48100E21 1STG ECM FURNACE & \$1520.87 ea\\\hline
211134 & 925SA66120E24 & 925SA66120E24 1STG ECM FURNACE & \$1595.16 ea\\\hline
\end{longtable}
\addcontentsline{toc}{section}{Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 95\% Preferred Two-Stage ECM--925TA}
\begin{longtable}{|p{.625in}|p{1.5in}|p{2.75in}|p{.875in}|}
\caption{
\ifimportant
\protect\includegraphics[width=1.875in,height=1.875in,keepaspectratio,right]{Bry_90_GasFurnacePhoto_9.jpg}
\global\importantfalse
Important is false
\fi
Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 95\% Preferred Two-Stage ECM--925TA}\\
\hline
Product\# & Model\# & Description & Price\\
\hline
\endfirsthead
\caption[]{
\protect\includegraphics[width=1.875in,height=1.875in,keepaspectratio,right]{Bry_90_GasFurnacePhoto_9.jpg}
\global\importantfalse
Important is false 2
Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 95\% Preferred Two-Stage ECM--925TA}\\
\hline
Product\# & Model\# & Description & Price\\
\hline
\endhead
335968 & 925TA60100E21 & 925TA60100E21 2STG ECM FURNACE & \$1818.50 ea\\\hline
212066 & 925TA66120E24 & 925TA66120E24 2STG ECM FURNACE PLEASE SEE 986TB & \$2020.93 ea\\\hline
\end{longtable}
\addcontentsline{toc}{section}{Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 96\% Evolution Two-Stage Variable--986T}
\begin{longtable}{|p{.625in}|p{1.5in}|p{2.75in}|p{.875in}|}
\caption{
\ifimportant
\protect\includegraphics[width=1.875in,height=1.875in,keepaspectratio,right]{Bry_90_GasFurnacePhoto_9.jpg}
\global\importantfalse
Important is false
\fi
Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 96\% Evolution Two-Stage Variable--986T}\\
\hline
Product\# & Model\# & Description & Price\\
\hline
\endfirsthead
\caption[]{
\protect\includegraphics[width=1.875in,height=1.875in,keepaspectratio,right]{Bry_90_GasFurnacePhoto_9.jpg}
\global\importantfalse
Important is false 2
Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 96\% Evolution Two-Stage Variable--986T}\\
\hline
Product\# & Model\# & Description & Price\\
\hline
\endhead
213086 & 986TA66120V24 & 986TA66120V24 EVO 2STG VS FURNACE & \$2104.24 ea\\\hline
448615 & 986TB42060V17 & 986TB42060V17 EVO 2STG VS FURNACE & \$1734.14 ea\\\hline
448616 & 986TB42080V17 & 986TB42080V17 EVO 2STG VS FURNACE & \$1796.61 ea\\\hline
448629 & 986TB60080V21 & 986TB60080V21 EVO 2STG VS FURNACE & \$1837.86 ea\\\hline
448661 & 986TB66100V21 & 986TB66100V21 EVO 2STG VS FURNACE & \$2065.30 ea\\\hline
448662 & 986TB66120V24 & 986TB66120V24 EVO 2STG VS FURNACE & \$2217.87 ea\\\hline
\end{longtable}
\addcontentsline{toc}{section}{Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 97\% Evolution Modulating Variable--987MA}
\begin{longtable}{|p{.625in}|p{1.5in}|p{2.75in}|p{.875in}|}
\caption{
\ifimportant
\protect\includegraphics[width=1.875in,height=1.875in,keepaspectratio,right]{Bry_90_GasFurnacePhoto_9.jpg}
\global\importantfalse
Important is false
\fi
Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 97\% Evolution Modulating Variable--987MA}\\
\hline
Product\# & Model\# & Description & Price\\
\hline
\endfirsthead
\caption[]{
\protect\includegraphics[width=1.875in,height=1.875in,keepaspectratio,right]{Bry_90_GasFurnacePhoto_9.jpg}
\global\importantfalse
Important is false 2
Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 97\% Evolution Modulating Variable--987MA}\\
\hline
Product\# & Model\# & Description & Price\\
\hline
\endhead
213244 & 987MA42060V17 & 987MA42060V17 EVO MOD VS FURNACE & \$2012.46 ea\\\hline
213456 & 987MA42080V17 & 987MA42080V17 EVO MOD VS FURNACE & \$2148.37 ea\\\hline
335981 & 987MA60080V21 & 987MA60080V21 EVO MOD VS FURNACE & \$2193.49 ea\\\hline
392719 & 987MA66100V21 & 987MA66100V21 EVO MOD VS FURNACE & \$2387.93 ea\\\hline
213711 & 987MA66120V24 & 987MA66120V24 EVO MOD VS FURNACE & \$2525.09 ea\\\hline
\end{longtable}
\clearpage\phantomsection
\end{document}
以下是生成的 PDF 的结果。如果您注意到第 4 页,它不会在第一个表格上显示图像,但会在第二个表格上显示。我希望它显示在第一个表格上,而不是第二个表格上:结果
答案1
好吧,试了一下。你混淆了 -command \caption
。下面是执行操作的一种方法。此外,你会发现我刚刚放了一 longtable
-环境,因为它演示了问题/解决方案。我还删除了代码中所有与手头任务无关的选项(实际上只是大多数,而不是全部)。所以这就是 MWE 的用途,希望现在更清楚了。
\documentclass[
fontsize=10pt,
a4paper,
DIV=15,
parskip=half
]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{
lmodern,
lipsum
}
\listfiles
%==================================================
%feel free to comment out the content up to this line and comment in lines 20--23
%==================================================
%\begin{document}
%\documentclass[
%8pt,
%]{report}
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage{caption}
\usepackage{longtable}
\usepackage{fancyhdr}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{hyperref}
\hypersetup{%
hidelinks=true
}
\begin{document}
\thispagestyle{empty}
\begin{center}
\fbox{Dummy text for your} \verb+\includegraphics+-commands\\
\huge Product Catalog\\
\vspace{.25in}
\large DOUG PETERSON
\vspace{.25in}
{\large{\today}}
\vfill
% Bottom of the page
{\large www.contractorshvacsupply.com}
\end{center}
\newpage
%\addchap{Residential Heating \& Cooling Equipment} %I strongly suggest using this variant! Must admit I do not get through the following lines.
\clearpage\phantomsection
\addcontentsline{toc}{chapter}{Residential Heating \& Cooling Equipment}
\markboth{Residential Heating \& Cooling Equipment}{}
\clearpage\phantomsection
\addcontentsline{toc}{section}{Bryant Residential - Bryant Furnaces - Bryant High Effciency Furnaces - 92\% Legacy Single-Stage--912BA}
Text.
\begin{center}
\captionof{table}{Bla text} %only works with a KOMA class (scrartcl, scrreprt or scrbook) or, if not KOMA class in use, with the package 'capt-of'
\begin{longtable}{|p{.625in}|p{1.5in}|p{2.75in}|p{.875in}|}
\multicolumn{4}{c}{\fbox{Dummy text for your \texttt{graphic}}}\\
\hline
Product\# & Model\# & Description & Price\\
\hline
\endhead
\hline
\multicolumn{4}{r}{\emph{continued on next page}}
\endfoot
\hline
\hline
\endlastfoot
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
394688 & 912SB48100S21 & 912SB48100S21 1STG 92 FURNACE & \$1285.43 ea\\
\end{longtable}
\end{center}
\end{document}