0

I've been battling with this problem trying to get this to work properly. I have a complex group of longtables I'm trying to get to display right.

What I'm trying to do is compile a catalog together. What I'm doing is if there are groups that share the same image, I only want to display the graphic above the first table, provided these groups appear on the same page. If the table spans to the next page, or if there is another group that shares the same image that then appears on the next page, I want it to display again, just above the top group.

I'm using PHP to generate the tex code, and it does the check to determine if the groups use the same image, and doesn't display it if it meets these parameters. I've got it working in every case except for 1, and that's when a new group that has the same image gets shoved to a new page because it won't fit. I don't know of a way to "programmatically" detect it is now on a new page, and therefore needs to have the image displayed. I'm trying to do a flag that gets set using AddEverypageHook, and it works, but must set it after the table has been generated, cause the image instead appears on the table that follows. Makes sense, because I suspect it generates the table first, determines it needs a new page and shoves it, and THEN sets the flag (which means it has set the flag after the point it would have needed to insert the image). I have some code that should generate a PDF that shows what I'm trying to do.

In this example, all groups of products share the same image, and so the only tables that should display an image should be the first tables on each page. This won't always be the case, however. If there is a different group that uses a different image, it will display over the new group with the new image (continuing on the same page), so it won't always just be the top image that displays. After you generate it (it may take a few times running it to get all the data to generate properly), if you look at page 4, you will notice that it does not display above the first group, but does above the second.

\documentclass[8pt]{report}
\usepackage[demo]{graphicx}
\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}
\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
\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]{}~\\[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


\begin{longtable}{|p{.625in}|p{1.5in}|p{2.75in}|p{.875in}|}
    \caption{
    \ifimportant
    \protect\includegraphics[width=1.875in,height=1.875in,keepaspectratio,right]{}
    \global\importantfalse
        \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]{}
    \global\importantfalse
    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]{}
    \global\importantfalse
        \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]{}
    \global\importantfalse
    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]{}
    \global\importantfalse
        \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]{}
    \global\importantfalse
    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]{}
    \global\importantfalse
        \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]{}
    \global\importantfalse
    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]{}
    \global\importantfalse
        \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]{}
    \global\importantfalse
    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]{}
    \global\importantfalse
        \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]{}
    \global\importantfalse
    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}
\end{document}

The following is a screenshot of an example of potential things the catalog might encounter: Sample Screenshot

If you notice, the first group has 1 image, but the next group has another image that spans multiple pages, as does the next, so it gets pretty complicated.

5
  • isn't this the same question as tex.stackexchange.com/questions/205484/… Commented Oct 14, 2014 at 22:55
  • Yes, but I'd already marked that one as solved...but it didn't really solve my problem. I tried to include a better working example and extra clarification in this one to try to make it easier for everyone.
    – CGRemakes
    Commented Oct 14, 2014 at 22:58
  • OK, I suppose:-) Commented Oct 14, 2014 at 23:00
  • do you really want the image in the caption? (potentially copied to list of tables and the page head)? Commented Oct 14, 2014 at 23:06
  • I could probably use a multicolumn for all that, though I don't "think" that would fix my problem. Let me know if you think it would make a difference.
    – CGRemakes
    Commented Oct 15, 2014 at 15:21

0

You must log in to answer this question.

Browse other questions tagged .