1

I want to use different background images within a letter I created with scrlttr2, on the first page image A and on all other pages image B.

Here is a working minimal example to use the same background on all pages.

Unfortunately I have no idea how to change this so that it works the way I described it.

\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}

Regards, Robert

1

You can load package scrlayer-scrpage, declare a new layer and add this layer to the special layer page style @everystyle@ (see the documentation).

\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}

Result:

enter image description here

It is also possible to have more than one letter in a 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}

enter image description here


It is also possible to declare a layer for the first letter page and another for next pages:

\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}

The result is the same as above.


Additional suggestion using 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}
1
  • Thanks, @esdd! You really saved my day. Your eso-pic solution works perfect!
    – Robert
    Jan 16 '20 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.