我想在我创建的信件中使用不同的背景图像scrlttr2
,在第一页上使用图像 A,在所有其他页面上使用图像 B。
这是一个可行的最小示例,在所有页面上使用相同的背景。
不幸的是,我不知道如何改变它以使其按照我描述的方式工作。
\documentclass[%%
fontsize=12pt,
paper=a4,
DIV=15,
version=last
]{scrlttr2}
\usepackage{fontspec}
\usepackage{microtype}
\usepackage{graphicx}
\usepackage{eso-pic}
\usepackage{blindtext}
\newcommand\BackgroundPic{
\put(0,0){
\parbox[b][\paperheight]{\paperwidth}{%
\centering
\includegraphics[width=\paperwidth,height=\paperheight]{picture.pdf}
}}}
\begin{document}
\AddToShipoutPicture{\BackgroundPic}
\begin{letter}{Address}
\setkomavar{subject}{Letter}
\opening{Sir}
\Blindtext
\end{letter}
\end{document}
问候,罗伯特
答案1
您可以加载包scrlayer-scrpage
,声明一个新层并将该层添加到特殊层页面样式中@everystyle@
(参见文档)。
\documentclass[%
%fontsize=12pt,% default
%paper=a4,% default
DIV=15,
%version=last% default
]{scrlttr2}
\usepackage{blindtext}% only for dummy text
\usepackage{fontspec}
\usepackage{microtype}
\usepackage{graphicx}
\usepackage{scrlayer-scrpage}
\DeclareNewLayer[
background,
mode=picture,
contents=\putLL{%
\ifnum \value{page}=1
\includegraphics[width=\layerwidth,height=\layerheight]{example-image-a}%
\else
\includegraphics[width=\layerwidth,height=\layerheight]{example-image-b}%
\fi
}
]{letterbackground}
\AddLayersToPageStyle{@everystyle@}{letterbackground}
\begin{document}
\begin{letter}{Address}
\setkomavar{subject}{Letter}
\opening{Sir}
\Blindtext[10]
\end{letter}
\end{document}
结果:
一个文档中也可能有多个字母:
\documentclass[
%fontsize=12pt,% default
%paper=a4,% default
DIV=15,
%version=last% default
]{scrlttr2}
\usepackage{blindtext}% only for dummy text
\usepackage{fontspec}
\usepackage{microtype}
\usepackage{graphicx}
\usepackage{scrlayer-scrpage}% sets page style scrheadings automatically
\DeclareNewLayer[
background,
mode=picture,
contents=\putLL{%
\ifnum \value{page}=1
\includegraphics[width=\layerwidth,height=\layerheight]{example-image-a}%
\else
\includegraphics[width=\layerwidth,height=\layerheight]{example-image-b}%
\fi
}
]{letterbackground}
\AddLayersToPageStyle{@everystyle@}{letterbackground}%
\begin{document}
\begin{letter}{Address}
\setkomavar{subject}{Letter}
\opening{Sir}
\Blindtext[10]
\end{letter}
\begin{letter}{Address}
\setkomavar{subject}{Letter}
\opening{Sir}
\Blindtext
\end{letter}
\end{document}
还可以为第一封信的页面声明一个层,为后续页面声明另一个层:
\documentclass[%
%fontsize=12pt,% default
%paper=a4,% default
DIV=15,
%version=last% default
]{scrlttr2}
\usepackage{blindtext}% only for dummy text
\usepackage{fontspec}
\usepackage{microtype}
\usepackage{graphicx}
\usepackage{scrlayer-scrpage}
\DeclareNewLayer[
background,
mode=picture,
contents=\putLL{\includegraphics[width=\layerwidth,height=\layerheight]{example-image-a}}
]{letterbackground.firstpage}
\DeclareNewLayer[
background,
mode=picture,
contents=\putLL{\includegraphics[width=\layerwidth,height=\layerheight]{example-image-b}}
]{letterbackground.nextpage}
\AddLayersToPageStyle{empty}{letterbackground.firstpage}% first letter page uses page style empty
\AddLayersAtBeginOfPageStyle{scrheadings}{letterbackground.nextpage}
\begin{document}
\begin{letter}{Address}
\setkomavar{subject}{Letter}
\opening{Sir}
\Blindtext[10]
\end{letter}
\begin{letter}{Address}
\setkomavar{subject}{Letter}
\opening{Sir}
\Blindtext
\end{letter}
\end{document}
结果和上面一样。
附加建议使用eso-pic
:
\documentclass[
%fontsize=12pt,% default
%paper=a4,% default
DIV=15,
%version=last% default
]{scrlttr2}
\usepackage{fontspec}
\usepackage{microtype}
\usepackage{graphicx}
\usepackage{eso-pic}
\usepackage{blindtext}
\newcommand\BackgroundPic{
\put(0,0){% <- needed to avoid a spurious space
\parbox[b][\paperheight]{\paperwidth}{%
\centering
\ifnum \value{page}=1
\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}%
\else
\includegraphics[width=\paperwidth,height=\paperheight]{example-image-b}%
\fi
}}}
\AddToShipoutPicture{\BackgroundPic}
\begin{document}
\begin{letter}{Address}
\setkomavar{subject}{Letter}
\opening{Sir}
\Blindtext[10]
\end{letter}
\begin{letter}{Address}
\setkomavar{subject}{Letter}
\opening{Sir}
\Blindtext
\end{letter}
\end{document}