1

I try to create multipage environment for output list of components. This list may be located in any part of the document (in the middle for example). I can create such list environment which work like this:

\documentclass[14pt,a4paper]{extreport}
\usepackage[a4paper,margin=2cm,right=1cm]{geometry}
\usepackage{longtable}
\usepackage{tikz}
\usepackage{eso-pic}
\usepackage{lipsum}

\newenvironment{elementlist}{%
  \newpage
  \pagestyle{empty}
  \linespread{1.34}\selectfont
  \enlargethispage{-3\baselineskip}
  \begin{longtable}[|c|]{@{}p{19mm}@{\hspace{2mm}}p{108mm}@{\hspace{2mm}}p{8mm}@{\hspace{2mm}}p{43mm}@{\hspace{1mm}}@{}}%
  }{%
  \end{longtable}%
  \ClearShipoutPicture
  \newpage 
 }%

\begin{document}
 \lipsum[3-6]
 \begin{elementlist}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \end{elementlist}
\lipsum[7-16]
\end{document}

enter image description here

Now I need a background frames on all environment pages. But first background frame have to be different from other page background farmes. Background frames I create as fllow:

\def\FormFirst{
\pagestyle{empty}
\ClearShipoutPicture
{\AddToShipoutPicture*{%
\begin{tikzpicture}[overlay]
\draw[black, line  width=0.5mm] ( 2.0, 0.5) rectangle (20.5, 29.2);
\draw[black, line  width=0.5mm] ( 2.0, 0.5) rectangle (20.5, 4.5);
\end{tikzpicture}}}}

\def\FormPosterior{
\pagestyle{empty}
\ClearShipoutPicture
{\AddToShipoutPicture*{%
\begin{tikzpicture}[overlay]
\draw[black, line  width=0.5mm] ( 2.0, 0.5) rectangle (20.5, 29.2);
\draw[black, line  width=0.5mm] ( 2.0, 0.5) rectangle (20.5, 2.0);
\end{tikzpicture}}}} 

And I know how place \FormFirst on first environment page:

\newenvironment{elementlist}{%
\FormFirst
  \newpage
  \pagestyle{empty}
  \linespread{1.34}\selectfont
  \enlargethispage{-3\baselineskip}
  \begin{longtable}[|c|]{@{}p{19mm}@{\hspace{2mm}}p{108mm}@{\hspace{2mm}}p{8mm}@{\hspace{2mm}}p{43mm}@{\hspace{1mm}}@{}}%
  }{%
  \end{longtable}%
  \ClearShipoutPicture
  \newpage 
  }%

But how place \FormPosterior on posterior environment list pages? enter image description here

1 Answer 1

1

You can do it like this. Note that you should use \clearpage: If you happen to be already on a new page, nothing happens, whereas \newpage will start a new page in any case. See the comments in the code for explanations.

\newif\ifFirstBackground % Flag to signal whether it's the first page
\newenvironment{elementlist}%
  {\clearpage
   \pagestyle{empty}%
   \ClearShipoutPicture % Just in case there are any leftovers; not really needed
   \FirstBackgroundtrue
   \AddToShipoutPicture{\Background}%
   %%% begin code for foreground
  }%
  {%%% end code for foreground
   \clearpage
   \ClearShipoutPicture % set everything back to normal
   \pagestyle{plain}%
  }

\newcommand\Background % choose an appropriate background depending on flag "FirstBackground"
  {\ifFirstBackground
     \BackgroundPicture{4.5}%
     \global\FirstBackgroundfalse
   \else
     \BackgroundPicture{2.0}%
   \fi
  }

\newcommand\BackgroundPicture[1]%
  {\begin{tikzpicture}[overlay]
   \draw[black, line  width=0.5mm] ( 2.0, 0.5) rectangle (20.5, 29.2);
   \draw[black, line  width=0.5mm] ( 2.0, 0.5) rectangle (20.5, #1);
   \end{tikzpicture}
  }

enter image description here enter image description here enter image description here

\documentclass[14pt,a4paper]{extreport}
\usepackage[a4paper,margin=2cm,right=1cm]{geometry}
\usepackage{longtable}
\usepackage{tikz}
\usepackage{eso-pic}
\usepackage{blindtext}

\newif\ifFirstBackground
\newenvironment{elementlist}%
  {\clearpage
   \pagestyle{empty}%
   \ClearShipoutPicture % Just in case there are any leftovers
   \FirstBackgroundtrue
   \AddToShipoutPicture{\Background}%
   \linespread{1.34}\selectfont
   \enlargethispage{-3\baselineskip}%
   \begin{longtable}[c] {@{}p{19mm}@{\hspace{2mm}}p{108mm}@{\hspace{2mm}}p{8mm}@     {\hspace{2mm}}p{43mm}@{\hspace{1mm}}@{}}%
  }%
  {\end{longtable}%
   \clearpage
   \ClearShipoutPicture
   \pagestyle{plain}%
  }

\newcommand\Background
  {\ifFirstBackground
     \BackgroundPicture{4.5}%
     \global\FirstBackgroundfalse
   \else
     \BackgroundPicture{2.0}%
   \fi
  }

\newcommand\BackgroundPicture[1]%
  {\begin{tikzpicture}[overlay]
   \draw[black, line  width=0.5mm] ( 2.0, 0.5) rectangle (20.5, 29.2);
   \draw[black, line  width=0.5mm] ( 2.0, 0.5) rectangle (20.5, #1);
   \end{tikzpicture}
  }

\newcommand{\lline}[4]{%
  \makebox[19mm]{#1} & %
  #2 & %
  \makebox[8mm]{#3} & %
  #4 %
  \tabularnewline}%

\newcommand{\element}[4]{%
  \lline{#1}{#2}{#3}{#4}}%

\newcommand{\Part}[1]{%
  \lline{}{\hfill \raisebox{0mm}[0mm][0mm]{#1} \hfill}{}{}}%

\begin{document}
\Blindtext
 \begin{elementlist}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
 \element{C15}{X7R~0805~0,47~uF}{1}{Phillips}
\end{elementlist}
\Blindtext
\end{document}
5
  • Thaks for the answer. But I want use new environment not only at begin of document. If I use this environment after some text \newpage result will be predictable. Title background appears under the some text, but I need backgrounds only for environment.
    – Konstantin
    Commented Jan 13, 2017 at 4:48
  • @Konstantin First, I don't yet understand what you really want to achieve. Can you post the non-working code (containing also \FormPosterior; currently your code doesn't use it) and explain what it is supposed to do? Second, the problem with putting commands like your \FormFirst and \FormPosterior anywhere into other macros is that it is difficult to keep control over the order in which these statements are executed: It may happen that part of the second page has been already processed before the first page is shipped out.
    – gernot
    Commented Jan 13, 2017 at 8:22
  • How can I post code and expectation example? Should i edit my first post?
    – Konstantin
    Commented Jan 13, 2017 at 8:46
  • I have changed first post. Try to make problem clearly.
    – Konstantin
    Commented Jan 13, 2017 at 11:12
  • @Konstantin I've modified the answer.
    – gernot
    Commented Jan 13, 2017 at 11:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .