我尝试创建多页环境来输出组件列表。此列表可能位于文档的任何部分(例如在中间)。我可以创建这样的列表环境,其工作方式如下:
\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}
现在我需要在所有环境页面上使用背景框架。但首先背景框架必须与其他页面背景框架不同。我创建的背景框架如下:
\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}}}}
而且我知道如何放置\FormFirst
在第一个环境页面上:
\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
}%
答案1
您可以这样做。请注意,您应该使用\clearpage
:如果您恰好已经在新页面上,则不会发生任何事情,而\newpage
无论如何都会开始一个新页面。请参阅代码中的注释以获取解释。
\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}
}
\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}