我对 LaTeX 完全陌生,现在我正在尝试找出一切是如何工作的。对于以下代码,我只在第一页上获得了背景图片,尽管我希望它出现在所有奇数页上。此外,我收到一条错误信息,指出:
未定义的控制序列:\AddEverypageHook
这是我的代码:
\documentclass[a4paper]{report}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{ifthen}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{eso-pic}
\newcommand\BackgroundPic{
\put(-4,0){
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\includegraphics[width=\paperwidth,height=\paperheight,
keepaspectratio]{background.jpg}%
\vfill
}}}
\makeatletter
\AddEverypageHook{%
\ifthenelse{\isodd{\value{page}}}%
{}%
{\AddToShipoutPicture*{\BackgroundPic}}%
}
\makeatother
\begin{document}
\title{The Triangulation of Titling Data in
Non-Linear Gaussian Fashion via $\rho$ Series}
\date{October 31, 475}
\author{John Doe\\ Magic Department, Richard Miles University
\and Richard Row, \LaTeX\ Academy}
\maketitle
\blinddocument
\end{document}
如果你能帮我解决这个问题并解释一下这里出了什么问题,那就太好了。提前谢谢了。
答案1
这eso-pic
包裹做不是提供\AddEverypageHook
,因此出现“未定义的控制序列”错误。后者由everypage
包裹。然而,由于eso-pic
负载atbegshi
默认情况下,您可以使用它提供的功能来利用页面输出例程。
看起来您是在文档的每个奇数/偶数页上打印一些背景图像。以下是这样做的:
\documentclass[a4paper]{report}
\usepackage[english]{babel}% http://ctan.org/pkg/babel
%\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{ifthen}% http://ctan.org/pkg/ifthen
\usepackage{blindtext}% http://ctan.org/pkg/blindtext
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{eso-pic}% http://ctan.org/pkg/eso-pic
\newcommand\BackgroundPic{%
\put(-4,0){%
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{tiger}%
\vfill
}}}
%\makeatletter
\AtBeginShipout{%
\ifthenelse{\isodd{\value{page}}}%
{}%
{\AddToShipoutPictureBG*{\BackgroundPic}}%
}
%\makeatother
\begin{document}
\title{The Triangulation of Titling Data in
Non-Linear Gaussian Fashion via $\rho$ Series}
\date{October 31, 475}
\author{John Doe\\ Magic Department, Richard Miles University
\and Richard Row, \LaTeX\ Academy}
\maketitle
\blinddocument
\end{document}
以下是一些进一步的考虑因素:
将图像放置在“背景层”中,
eso-pic
同时\AddToShipoutPictureBG
将\AddToShipoutPictureFG
其打印在“前景层”中。每个都有一个带星号的变体,与仅有的调用该页面的页面。没有\AddToShipoutPicture
(没有BG
或FG
)。图片添加基于
\value{page}
,因此任何影响页码的命令都会对位置产生影响(例如标题)。
答案2
这是一个解决方案雙水印包裹。
\documentclass{article}
\makeatletter
\usepackage[dvipsnames]{xcolor}
%\usepackage[colorlinks,pdfview=FitB]{hyperref}
\usepackage[printwatermark]{xwatermark}[2012/02/01]
% Local watermark locations:
\watermarkpaths{{./}{./Graphics/}}
% \newwatermark has a key-value interface. There are many more keys; see the
% package documentation. 'oddpages' means 'put watermarks on odd pages only'.
\newwatermark[
oddpages,coordunit=pc,fontfamily=put,textcolor=BurntOrange,fontsize=5cm,
textalign=center,textangle=45,picangle=0,textxpos=-4,textypos=4,picxpos=0,
picypos=0,picontoptext,picbb=127 203 527 672,picscale=.6,picfile=mindmap1,
picfileext=pdf
]{MIND}
% Get the dimensions of the graphics 'comet1':
\xwmgetpicdim[scale=.5,viewport=20 21 590 400]{comet1}
% Put 'comet1' on odd pages, at the given positons:
\repeatwatermarks[Page=\thepage]{%
oddpages,coordunit=pc,picbb=20 21 590 400,picscale=.5,picfile=comet1,
textontoppic,fontsize=2.5cm,textcolor=white
}{%
picxpos=-.5\paperwidth+\xwmwdofpic/2,picypos=-.5\paperheight+\xwmtothtofpic/2,
textxpos=-.5\paperwidth+\xwmwdofpic/2,textypos=-.5\paperheight+\xwmtothtofpic/2;
picxpos=-.5\paperwidth+\xwmwdofpic/2,picypos=.5\paperheight-\xwmtothtofpic/2,
textxpos=-.5\paperwidth+\xwmwdofpic/2,textypos=.5\paperheight-\xwmtothtofpic/4;
picxpos=.5\paperwidth-\xwmwdofpic/2,picypos=-.5\paperheight+\xwmtothtofpic/2,
textxpos=.5\paperwidth-\xwmwdofpic/2,textypos=-.5\paperheight+\xwmtothtofpic/2;
picxpos=.5\paperwidth-\xwmwdofpic/2,picypos=.5\paperheight-\xwmtothtofpic/2,
textxpos=.5\paperwidth-\xwmwdofpic/2,textypos=.5\paperheight-\xwmtothtofpic/4
}
\begin{document}
xx
\newpage
yy
\newpage
zz
\newpage
aa
\newpage
bb
\end{document}
该图仅显示输出的第 1 页。