\myTileWallPaper
在类文件中定义如下
\makeatletter
\newcommand{\myTileWallPaper}[4]{%
\begingroup
\setlength{\tileYoffset}{\wpYoffset}
\setlength{\tilewidth}{#1}%
\setlength{\tileheight}{#2}%
\setlength{\tileY}{0pt}%
\whiledo{\lengthtest{\tileY < \paperheight}}{%
\setlength{\tileX}{0pt}%
\setlength{\tileXoffset}{\wpXoffset}%
\whiledo{\lengthtest{\tileX < \paperwidth}}{%
\put(\LenToUnit{\tileXoffset},\LenToUnit{\tileYoffset}){%
\includegraphics[height=\tileheight,width=\tilewidth]{#3}}%
\addtolength{\tileX}{\tilewidth}
\addtolength{\tileXoffset}{\tilewidth}
}%
\addtolength{\tileY}{\tileheight}
\addtolength{\tileYoffset}{\tileheight}
}%
\endgroup
}
\makeatother
当我使用两个\AddToShipoutPicture
s 时,LaTeX 会抛出错误。
\AddToShipoutPicture{%
\ifthenelse{\isodd{\thepage}}% Wenn ungerade Seitenzahl, dann Bild 1, sonst Bild 2.
{\myTileWallPaper{\paperwidth}{\paperheight}{wallpaper1}}% ungerade Seite
{\myTileWallPaper{\paperwidth}{\paperheight}{wallpaper2}}% gerade Seite
}
\AddToShipoutPicture{\setlength{\unitlength{0.1mm}}\put(500,2522){\includegraphics[width=1.5cm]{Logoimg}}}
错误如下:
! Missing number, treated as zero.
<to be read again>
{
l.73 \end{document}
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)
如果我删除第二个\AddToShipoutPicture
,一切似乎都正常。如果我删除第二个\AddToShipoutPicture
并将其放在第一个之前,一切似乎都正常——尽管它不起作用,因为墙纸随后覆盖了徽标。
答案1
以下平铺并不完全正确,但如果您的代码编译成功,它正是您应有的样子。例如,使用雙水印包。
\usepackage{graphicx}
\usepackage{catoptions}
\usepackage{eso-pic}
\makeatletter
\cptnewdimens{tileXoffset,tileYoffset,wpXoffset,wpYoffset,
tilewidth,tileheight,tileX,tileY}
\wpXoffset.25cm\wpYoffset.25cm
\robust@def*\myTileWallPaper#1#2#3{%
\begingroup
\tileYoffset\wpYoffset
\tilewidth=\dimexpr#1\relax
\tileheight=\dimexpr#2\relax
\tileY=0pt
\cptwhiledim\tileY<\paperheight\do{%
\tileX=0pt \tileXoffset\wpXoffset
\cptwhiledim\tileX<\paperwidth\do{%
\put(\LenToUnit{\tileXoffset},\LenToUnit{\tileYoffset}){%
\includegraphics[height=\tileheight,width=\tilewidth]{#3}%
}%
\addtolength{\tileX}{\tilewidth}%
\addtolength{\tileXoffset}{\tilewidth}%
}%
\addtolength{\tileY}{\tileheight}%
\addtolength{\tileYoffset}{\tileheight}%
}%
\endgroup
}
\makeatother
\begin{document}
\AddToShipoutPicture{%
\ifnumoddTF\thepage
{\myTileWallPaper{.25\paperwidth}{.25\paperheight}{diag1.eps}}%
{\myTileWallPaper{.25\paperwidth}{.25\paperheight}{diag2.eps}}%
}
这是正确的解决方案。现在您使用键代替参数。
\documentclass{article}
\usepackage{atbegshi,picture,graphicx,ifpdf}
\usepackage{pathkeys}
\makeatletter
\pathkeys{wallpaper/asif/define*(cmd):
viewport/00 00 100 100;
xtilenr/2;
ytilenr/2;
wpxoffset/0pt;
wpyoffset/0pt;
inputpath//;
}
\newcommand*\mytilewallpaper[2][]{%
\begingroup
\pathkeys@currentpath{wallpaper/asif}%
\pathkeys{set:#1}%
\pathkeys@useshortcmds
\edef\ffileext{\ifpdf pdf\else eps\fi}%
\edef\reserved@a{\pkv{inputpath}}%
\edef\reserved@a{\expandafter\ltxkeys@stripallouterbraces
\expandafter{\reserved@a}}%
\edef\Ginput@path{\ifcsnullTF\reserved@a{}{{\reserved@a/}}}%
\cptdimdef\tilewidth{(\paperwidth-\pkv{wpxoffset}*2)/\pkv{xtilenr}}%
\cptdimdef\tileheight{(\paperheight-\pkv{wpyoffset}*2)/\pkv{ytilenr}}%
\cptdimdef\tileY{-\paperheight+\pkv{wpyoffset}}%
\@tempcntb\z@
\cptwhilenum\@tempcntb<\pkv{ytilenr}\do{%
\edef\tileX{\pkv{wpxoffset}}%
\@tempcnta\z@
\cptwhilenum\@tempcnta<\pkv{xtilenr}\do{%
\leavevmode\@killglue
\cptexpanded{\noexpand\put(\tileX,\tileY){\noexpand\includegraphics
[viewport=\pkv{viewport},height=\tileheight,
width=\tilewidth,clip]{#2.\ffileext}}}%
\advance\@tempcnta\@ne
\cptdimadd\tileX{\tilewidth}%
}%
\advance\@tempcntb\@ne
\cptdimadd\tileY{\tileheight}%
}%
\endgroup
}
\makeatother
\begin{document}
\def\wpspec{[viewport=20 21 590 400,xtilenr=4,ytilenr=4,
wpxoffset=2cm,wpyoffset=2cm,inputpath={./graphics}]{comet1}}
\AtBeginShipout{%
\AtBeginShipoutUpperLeft{%
\ifnumoddTF\thepage
{}%
{\expandafter\mytilewallpaper\wpspec}%
}}
x
\newpage
x
\end{document}